A graph search enhancement-based large language model fine-tuning data synthesis method

CN122885140APending Publication Date: 2026-10-09FUJIAN FUYAO UNIVERSITY OF SCIENCE & TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611343887.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-01
Publication Date
2026-10-09

AI Technical Summary

Technical Problem

此类方法虽在一定程度上实现了跨文档信息关联,但其路径扩展机制存在如下不足:纯拓扑遍历方式缺乏对路径语义聚焦性的保证;引入模型置信度评估的引导方式,其判断依据本身由模型生成,易受模型校准偏差影响,路径选择的可控性不足;而无语义约束的随机选择方式虽引入了随机性,却缺乏语义聚焦控制,容易盲目发散

Benefits of technology

[0024]相比于现有技术,本发明及其优选方案通过反向哈希溯源指针将图谱元素与其来源文本切片绑定,并在生成阶段将路径骨架链与原始文本切片跨文本拼接,本发明使合成数据能够在保持图谱宏观逻辑结构的同时复用原始语料的细粒度语境,从而聚合跨文档、跨段落的多源信息,支持需要多步推理的复杂问题的构建;通过社区划分与配额化选种、路径累计语义聚合、相似度截断与候选池内均匀随机采样的组合机制,本发明在保证路径延伸方向与已积累语义高度相关的前提下引入受控的随机选择,使合成数据的分布覆盖与结构多样性得到提升,缓解了纯拓扑遍历语义聚焦不足、基于大语言模型语义判断的子图抽取方式受模型生成偏好影响以及无语义约束的随机扩展容易盲目发散等问题;通过忠实性、相关性、完整性三个维度的系统性评估,以及未通过时以批评意见驱动定向优化重写、以最大重试次数兜底的闭环机制,本发明能够过滤事实幻觉、浅层复述与逻辑断裂数据,提升微调数据集的可靠性与推理深度;上述环节构成从语料输入到微调数据输出的自动化流水线,无需人工编写种子指令和逐条核验,降低了知识蒸馏的数据构建成本,为算力、内存与功耗受限场景下小规模语言模型的监督微调提供了数据基础。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122885140A_ABST
    Figure CN122885140A_ABST
Patent Text Reader

Abstract

The application provides a kind of based on graph retrieval enhancement's large model fine-tuning data synthesis method, belongs to natural language processing and big language model technical field.The method extracts entity and relationship after dividing text corpus into blocks and constructs directed knowledge graph, establishes reverse hash traceability pointer pointing to source text slice for each graph element, and maps relationship edge into semantic feature vector;Perform mixed semantic topology truncated random walk on knowledge graph, select starting seed by community division, aggregate path features that have been walked to form cumulative state vector, uniformly randomly sample multiple-hop paths in candidate pool after truncating candidate neighbors by cosine similarity;Pull the original text slice through the reverse hash traceability pointer, form a composite context after translating the path into a skeleton chain and cross-text splicing the original text, input the teacher large language model to generate candidate question-answer pairs;From the fidelity, relevance, integrity three-dimensional evaluation, the question-answer pairs evaluated are included in the fine-tuning dataset.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of natural language processing and large language model technology, specifically relating to a method for fine-tuning data synthesis of large language models based on graph retrieval enhancement. Background Technology

[0002] Large-scale language models demonstrate powerful capabilities in natural language processing tasks, but their large parameter count and high inference costs make them difficult to deploy directly in resource-constrained environments such as IoT devices and edge computing nodes. Training small-scale language models through knowledge distillation to inherit the inference capabilities and alignment preferences of large models is an important way to reduce deployment costs. Among these approaches, automatically synthesizing instruction-question-answer data from a corpus using a teacher's large language model and then using this data to supervise and fine-tune the small-scale language model is currently the mainstream data construction method.

[0003] However, existing corpus-driven data synthesis methods still have significant shortcomings.

[0004] 1. Text block-based synthesis methods (such as Genie, Wrap, Self-QA, LongForm, etc.) typically pre-segment documents into isolated text blocks and synthesize question-and-answer data one by one. This severs the semantic relationships between entities within the same long document and between different documents, making the synthesized data mostly limited to simple questions and answers about a single local fact. It is difficult to form complex questions that require the aggregation of information from multiple sources to answer, and it is insufficient for training the multi-step reasoning ability of downstream small-scale language models.

[0005] 2. Knowledge graph-based synthesis methods (such as GraphGen) construct a graph by extracting entities and relations from documents, and generate question-and-answer data using multi-hop neighborhood sampling or subgraph extraction based on a large language model. While these methods achieve cross-document information association to some extent, their path expansion mechanisms have the following shortcomings: pure topological traversal lacks guarantees for semantic focus on paths; the guidance method that introduces model confidence evaluation, whose judgment criteria are generated by the model itself, is easily affected by model calibration bias, resulting in insufficient controllability of path selection; and while random selection without semantic constraints introduces randomness, it lacks semantic focus control and is prone to blind divergence. Furthermore, when generating question-and-answer data, these methods typically only use entity, relation, and attribute descriptions from the graph as input, without using subgraph elements as indexes to trace back and reuse the original text fragments from which they originated, making it easy to lose fine-grained contextual information during graph abstraction.

[0006] 3. The above methods mostly use a single generation approach when generating data. Even if some frameworks introduce quality checks, they are often limited to a single-dimensional check of the consistency between the answer and the given information. For example, they may verify whether the answer can be supported by evidence paths in the graph. They lack a multi-dimensional assessment of the relevance of the generated question and the integrity of the reasoning chain of the answer. It is difficult to systematically filter out shallow paraphrases, factual illusions and logically broken data, resulting in noise mixed into the synthetic data and affecting the reliability of the small-scale language model after fine-tuning.

[0007] In summary, there is an urgent need for an automated fine-tuning data synthesis method that can achieve cross-document information aggregation and improve the diversity and reasoning complexity of synthesized data while ensuring the accuracy of data facts. Summary of the Invention

[0008] To address the shortcomings and deficiencies of existing technologies, this invention provides a method for synthesizing large language model fine-tuning data based on graph retrieval enhancement. This method divides the text corpus into blocks, extracts entities and relationships between entities using a large language model, constructs a knowledge graph with entities as nodes and relationships as directed edges, and establishes reverse hash tracing pointers for the nodes and edges in the graph, pointing to their source text slices. Simultaneously, each relationship edge is mapped to a semantic feature vector. Based on this, a hybrid semantic topology truncation random walk is performed, incorporating community partitioning, cumulative semantic aggregation, similarity truncation, and uniform sampling within the candidate pool, generating a multi-hop path set that combines semantic focus and diversity. For each path, the original text slices it covers are recalled through the reverse hash tracing pointers, and these slices are concatenated with the skeleton chain obtained from path translation to form a composite context. This context is then used by a teacher's large language model to generate candidate question-answer pairs, which are then evaluated by an evaluation large language model based on three dimensions: fidelity, relevance, and completeness. Only those passing all three dimensions are included in the fine-tuning dataset for supervised fine-tuning of small-scale language models under resource-constrained environments.

[0009] To achieve the above objectives, this invention provides a method for fine-tuning data synthesis of large language models based on graph retrieval enhancement, comprising:

[0010] The text corpus is divided into multiple text slices. Entities and relationships between entities are extracted from each slice. A knowledge graph is constructed using entities as nodes and relationships as directed edges. A reverse hash tracing pointer is established for each node and edge, pointing to its source text slice. Each relationship edge is mapped to a semantic feature vector. Specifically, the reverse hash tracing pointer anchors the abstract nodes and edges in the graph to the original text slice from which they were initially extracted. This ensures that the underlying corpus is not discarded after the graph is constructed, and any subsequent generation stage can losslessly revert to the original context through this pointer, providing factual anchors for the generated content. The text representation of the relationship edges is encoded into high-dimensional dense semantic feature vectors and persistently mounted on the corresponding edges. This gives the discrete graph topology a numerical representation that can measure semantic similarity in mathematical space, providing a semantic foundation for path expansion.

[0011] The process of generating a multi-hop path set by performing a hybrid semantic topology truncated random walk on the knowledge graph includes: dividing the knowledge graph into communities, determining the starting node quota for each community based on its size, and selecting starting nodes within the corresponding communities according to the quota; starting from each starting node, aggregating the semantic feature vectors of each relation edge on the already visited path in each step of the walk to obtain a cumulative semantic state vector, calculating the cosine similarity between the feature vector of each candidate neighbor relation edge and the cumulative semantic state vector, eliminating neighbor nodes that do not meet a preset similarity threshold, selecting a preset number of nodes in descending order of similarity to form a candidate pool, uniformly and randomly sampling within the candidate pool to determine the next hop node, and ensuring that visited nodes are not revisited on the same path, until a preset depth limit is reached or there are no unvisited neighbor nodes that meet the preset similarity threshold, at which point the process terminates. The above-mentioned walk mechanism, which integrates community division, cumulative semantic aggregation of paths, similarity truncation, and uniform random sampling within the truncation pool, is collectively referred to as a hybrid semantic topology truncated random walk. In this system, candidate neighbors are the unvisited neighbor nodes of the current node, and the feature vector of the candidate neighbor relationship edge is the semantic feature vector of the relationship edge corresponding to the unvisited neighbor node. Community division and quota-based selection ensure that the starting point of the walk is evenly distributed across the macro theme, avoiding concentration in local areas where high-frequency entities are located. The cumulative semantic state vector dynamically aggregates the semantics of the edges already visited on the path as the walk progresses, so that the truncation criteria are adaptively adjusted with the path evolution, rather than relying solely on the local information at the current node. Threshold elimination and quantity truncation constitute a two-stage screening process of filtering first and then truncation. The former ensures that the elements in the candidate pool are highly correlated with the current semantic process, while the latter controls the size of the candidate pool for subsequent sampling. Uniform random sampling within the candidate pool introduces perturbed random selection within a controllable high correlation range, replacing deterministic greedy selection, so that the path can explore branches that are not fully covered but are still relevant. The same path does not repeatedly visit visited nodes, making the sampling no-replacement sampling. The termination condition of no unvisited neighbor nodes that meet the preset similarity threshold covers both the case where the current node has no unvisited neighbors and the case where there are unvisited neighbors but none of them have passed the threshold screening.

[0012] For each multi-hop path, the original text slices corresponding to each node and edge on the path are retrieved using a reverse hash tracing pointer. The path is then translated into a skeleton chain in text form, which is concatenated with the retrieved original text slices to form a composite context. The skeleton chain is a causal logic skeleton chain text obtained by translating entities and relationships along the path into natural language form, presenting the logical direction inherent in the path. The original text slices retain the micro-level fine-grained context. The combination of these two on the input side allows the composite context to simultaneously possess both macro-level cross-document reasoning structure and micro-level factual details, enabling the aggregation of multi-source information and the execution of multi-step reasoning during the generation stage, thus mitigating the problem of fine-grained context loss during graph abstraction.

[0013] The complex context is input into the teacher's large language model to generate candidate question-answer pairs. The teacher's large language model refers to a high-performance large language model that provides supervision signals to the student model in the knowledge distillation scenario, and it is constrained to generate candidate question-answer pairs within the scope of the complex context.

[0014] Candidate question-and-answer pairs and their complex contexts are input into an evaluation large language model, which is evaluated from three dimensions: fidelity, relevance, and completeness. Only those that pass all three dimensions are included in the fine-tuning dataset. The evaluation large language model can be either a teacher's large language model that triggers a role change to act as an evaluator, or a separate, independently set language model. The three dimensions target three common problems: factual illusion, shallow restatement, and logical breaks, respectively, forming a multi-dimensional quality gate for candidate question-and-answer pairs.

[0015] Furthermore, the community partitioning of the knowledge graph employs either the Leiden algorithm or the Louvain algorithm. The determination of the starting node quota for each community based on its size includes: for each community, the starting node quota is calculated as 5% of the community's total number of nodes and rounded down, with a value not less than 1 and not greater than 10; nodes from each community are selected in descending order of degree, matching the community's starting node quota. This lower limit ensures that even very small, long-tail communities can contribute starting nodes, preventing them from being completely ignored, while the upper limit prevents very large communities from occupying too much sampling share; both factors work together to ensure balanced sampling among communities. Selecting nodes in descending degree order ensures that the seed falls on tightly connected core nodes within the community. Considering that modularity optimization algorithms are typically designed for undirected graphs, as a preferred approach, community partitioning can be performed on the accompanying undirected graph after symmetrizing each directed edge, and the node degree can be the sum of the corresponding node's in-degree and out-degree.

[0016] Further, mapping each relation edge to a semantic feature vector includes: inputting the text of the relation triple corresponding to the relation edge into a pre-trained word embedding encoder to obtain a semantic feature vector. The pre-trained word embedding encoder includes BGE, E5, or Sentence-BERT, and the dimension of the semantic feature vector is 768 or 1024. Aggregating the semantic feature vectors of each relation edge on the already visited path includes: adding the semantic feature vectors of each relation edge on the already visited path element-wise to obtain a cumulative semantic state vector, or performing mean pooling on the semantic feature vectors of each relation edge on the already visited path to obtain a cumulative semantic state vector. Since cosine similarity is not affected by the overall vector scaling, element-wise addition and mean pooling are equivalent under this metric and do not produce different technical effects, so they can be selected according to engineering needs.

[0017] Furthermore, the preset similarity threshold ranges from 0.5 to 0.85; the preset number ranges from 5 to 15; when the number of neighbor nodes satisfying the preset similarity threshold is less than the preset number, all neighbor nodes satisfying the condition are selected to form a candidate pool; the preset depth upper limit ranges from 3 to 6. Wherein, a similarity threshold that is too low will cause neighbors with insufficient semantic relevance to enter the candidate pool, weakening the semantic focusing effect; a threshold that is too high may result in a candidate pool that is too small or even empty, limiting the diversity of path exploration; the preset number strikes a balance between candidate pool diversity and computational cost, and when the number of neighbors satisfying the threshold is less than the preset number, all of them are selected to avoid the candidate pool being too small, causing the path to terminate prematurely; the depth upper limit determines the number of reasoning hops for the path. Shorter paths are less likely to form complex tasks requiring multiple reasoning steps, while longer paths increase semantic drift and computational cost. Preferably, the similarity threshold can be 0.7, the preset number can be 10, and the depth upper limit can be 3.

[0018] Furthermore, the process of translating the path into a textual skeleton chain and concatenating it with the retrieved original text slices to form a composite context includes: translating entities and relationships along the multi-hop path into causal logic skeleton chain text; deduplicating the retrieved original text slices and sorting them according to their order of appearance in the original document; concatenating the causal logic skeleton chain text with the sorted original text slices using a preset delimiter to form a composite context; and truncating or summarizing the original text slices when the length of the composite context exceeds the preset context window limit. Deduplication is used to eliminate redundancy caused by the same slice being repeatedly recalled by multiple edges on the path. Sorting according to the order of appearance in the original document is used to maintain the coherence of the concatenated text. Delimiters are used to help the large language model distinguish between the structured skeleton and the original corpus as information sources. The context window limit is the maximum length of input that the large language model can process at one time. When the length exceeds the limit, the original text slice is truncated or summarized to ensure that the composite context can be consumed completely.

[0019] Furthermore, the evaluation from the three dimensions of fidelity, relevance, and completeness includes: fidelity checking whether the facts in the answer are fully supported by the composite context; if the answer contains entities, numerical values, or factual statements that do not exist in the composite context, fidelity is deemed unsatisfactory. Relevance checking whether the question covers and utilizes the causal relationships across multiple paths; if the answer can be directly derived from a single fact corresponding to a single edge in the multiple-hop path, relevance is deemed unsatisfactory. Completeness checking whether the reasoning chain of the answer is sufficiently supported and causally consistent; if the answer only provides a conclusion without providing reasoning steps or supporting arguments, or if the reasoning chain has causal breaks or contradictions, completeness is deemed unsatisfactory. These criteria translate the three dimensions into actionable trigger rules, making the evaluation process based on evidence. Among these, causal relationships across multiple paths refer to causal associations that require the aggregation of multi-source information to establish.

[0020] Furthermore, when a candidate question-answer pair fails the three-dimensional evaluation, the evaluation large language model simultaneously outputs criticisms. These criticisms, along with the composite context and the candidate question-answer pair, are input into the optimization large language model to generate an optimized question-answer pair. The generation of the optimized question-answer pair is executed using a preset optimization instruction template, which includes context variables, original question-answer variables, and criticism variables. The model is required to output optimized structured data containing the question and answer based on the criticisms. The optimized question-answer pair is then evaluated again in the three dimensions until it passes the evaluation or the optimization retries reach a preset maximum number of retries. If the maximum number of retries is reached and the candidate question-answer pair still fails, it is discarded. The criticisms enable rewriting to target specific defects identified during the evaluation, forming a closed loop of generation—evaluation—optimization—re-evaluation. The maximum number of retries avoids loops targeting samples that are difficult to correct; those that still fail after reaching the upper limit are discarded, preventing low-quality data from mixing into the fine-tuning signal. The optimized large language model can be either the teacher's large language model or another independently set large language model, preferably the teacher's large language model; as a preferred option, the preset maximum number of retries is 3.

[0021] Furthermore, the assessment language model employs a pre-defined three-dimensional reflection assessment instruction template. This template requires the model to output structured data containing three-dimensional assessment judgments and criticisms. The judgments are considered passed if and only if all three dimensions—fidelity, relevance, and completeness—are passed. The criticisms describe existing problems and provide suggestions for improvement. The teacher language model employs a pre-defined data synthesis instruction template. This template includes knowledge path variables and original context variables, requiring the model to output structured data containing questions and answers. The instruction template standardizes the model's output format, facilitating automated parsing and subsequent processing. Preferably, the structured data uses JSON format. For example, the output of the three-dimensional reflection assessment instruction template is an object containing a validity boolean field and a criticism field, while the output of the data synthesis instruction template is an object containing a question field and an answer field.

[0022] Furthermore, the text corpus is divided into multiple text slices using a sliding window approach, with slice lengths ranging from 512 to 2048 tokens and overlap between adjacent slices ranging from 10% to 30%. The extraction of entities and relationships between entities from each text slice is performed using a concurrent call to a large language model, and entity disambiguation is applied to the extraction results. Sliding window segmentation divides long texts into text blocks suitable for processing by a large language model, and the overlap between adjacent slices prevents entities and relationships from being severed at slice boundaries. Concurrent calls allow the extraction tasks of multiple slices to be executed in parallel, improving processing efficiency. Entity disambiguation merges different references to the same entity in different text slices into the same entity node, ensuring the global consistency of the knowledge graph. Preferably, the slice length is 1024 tokens, and the overlap ratio is 20%.

[0023] Accordingly, the present invention also provides a large language model fine-tuning data synthesis system based on graph retrieval enhancement, comprising: a knowledge graph construction module, used to divide a text corpus into multiple text slices, extract entities and relationships between entities from each text slice, construct a knowledge graph with entities as nodes and relationships as directed edges, establish a reverse hash tracing pointer for each node and edge pointing to its source text slice, and map each relationship edge to a semantic feature vector; a path expansion module, used to perform community division on the knowledge graph and select starting nodes, perform a hybrid semantic topology truncation random walk from each starting node to generate a set of multi-hop paths; a data synthesis module, used to, for each multi-hop path, pull the original text slices corresponding to each node and edge on the path through the reverse hash tracing pointer, translate the path into a skeleton chain in text form, concatenate it with the pulled original text slices across text to form a composite context, input the composite context into the teacher's large language model to generate candidate question-answer pairs; and a quality evaluation module, used to input the candidate question-answer pairs and their composite context into the evaluation large language model, evaluate them from three dimensions: fidelity, relevance, and completeness, and only include them in the fine-tuning dataset when all three dimensions pass. The above modules correspond to the various processing stages in the method and can be integrated into the same electronic device or deployed on different devices according to their functions. Preferably, the quality assessment module is also used to output criticisms and drive the optimization and rewriting of the question-answer pair when the assessment fails.

[0024] Compared to existing technologies, this invention and its preferred scheme bind graph elements to their source text slices through reverse hash tracing pointers, and concatenate the path skeleton chain with the original text slices across texts during the generation stage. This invention enables the synthesized data to reuse the fine-grained context of the original corpus while maintaining the macro-logical structure of the graph, thereby aggregating multi-source information across documents and paragraphs and supporting the construction of complex problems requiring multi-step reasoning. Through a combination mechanism of community partitioning and quota-based seeding, path cumulative semantic aggregation, similarity truncation, and uniform random sampling within the candidate pool, this invention introduces controlled random selection while ensuring that the path extension direction is highly correlated with the accumulated semantics. This improves the distribution coverage and structural diversity of the synthesized data, alleviating the problem of pure topological traversal. This invention addresses issues such as insufficient semantic focus, the influence of model generation preferences on subgraph extraction based on semantic judgment of large language models, and the tendency for random expansion without semantic constraints to diverge blindly. Through a systematic evaluation across three dimensions—fidelity, relevance, and completeness—and a closed-loop mechanism that drives targeted optimization and rewriting based on criticism when data fails, with a safety net of maximum retries, this invention filters out factual illusions, shallow restatements, and logically broken data, improving the reliability and inference depth of the fine-tuning dataset. These steps constitute an automated pipeline from corpus input to fine-tuning data output, eliminating the need for manual seed instruction writing and line-by-line verification, reducing the data construction cost of knowledge distillation, and providing a data foundation for supervised fine-tuning of small-scale language models in scenarios with limited computing power, memory, and power consumption. Attached Figure Description

[0025] Figure 1 This is a schematic diagram of the overall process of the method according to an embodiment of the present invention;

[0026] Figure 2 This is a comparison chart of the quality level distribution of the synthesis instructions in an embodiment of the present invention. Detailed Implementation

[0027] To make the features and advantages of the present invention more apparent and understandable, specific embodiments are described below in detail:

[0028] It should be noted that the following detailed descriptions are exemplary and intended to provide further explanation of this application. Unless otherwise specified, all technical and scientific terms used in this specification have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains.

[0029] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments according to this application. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0030] (I) Overview of Technical Solution

[0031] This invention provides a method for synthesizing large-scale model fine-tuning data based on graph retrieval enhancement. Through three core steps—constructing a knowledge base graph and embedding space, performing random truncation path expansion using hybrid graph topology and semantic embedding, and aggregating information across documents and evolving synthetic data in multiple dimensions—it achieves fully automated construction of highly diverse and complex fine-tuning instruction data. This enables small language models to better internalize the higher-order reasoning abilities and alignment preferences of large teacher models. Figure 1 As shown, the overall process of the method of the present invention includes three main stages: step S1 constructing a knowledge base graph and embedding space, step S2 path expansion of hybrid graph topology and semantic embedding, and step S3 cross-document evolution and synthesis of data.

[0032] In step S1, the system targets a large-scale unlabeled unstructured text corpus. In step S1.1, it performs sliding window segmentation and joint entity relation extraction based on structured knowledge extraction using a large model. In step S1.2, it constructs an instantiated knowledge graph with global connectivity using a knowledge base and embedding space. For each graph element, it establishes a reverse hash tracing pointer to the original text slice (which can be stored in the attribute fields of the corresponding nodes and edges in the graph database in the form of key-value mapping, with its value being the index identifier of the source text slice). The system also maps relation triples to high-dimensional dense semantic feature vectors.

[0033] In step S2, the system performs a hybrid semantic topology truncated random walk on the knowledge graph that integrates semantic focus and topology exploration: through topology awareness and dynamic allocation of seed numbers in S2.1, the knowledge graph is clustered by community and dynamically allocated to determine the starting seed; through semantically guided graph path expansion in S2.2, historical path features are aggregated in each walk and candidate neighbors are hard-truncated by cosine similarity, and uniform random sampling is used in the truncated candidate pool to determine the next hop, and finally a multi-hop candidate path set that combines semantic focus and diverse exploration is output.

[0034] In step S3, the system performs cross-document information aggregation in S3.1, using a reverse hash pointer to pull the original text slices corresponding to each node and edge on the multi-hop path, and physically splices the structured logical skeleton with the unstructured original text to form a composite context. Through multi-dimensional filtering evolution in S3.2, the composite context is fed into the teacher's big model to generate candidate question-answer pairs, and the synthetic data is iteratively optimized and filtered through a self-criticism mechanism of three dimensions: fidelity, relevance, and completeness, finally outputting a high-quality fine-tuned dataset.

[0035] (II) Construction of Knowledge Foundation Map and Embedded Space

[0036] This step aims to break down the physical isolation barriers between documents in traditional unstructured corpora. It utilizes large language models to extract entity and relational structures, constructing a low-level knowledge graph network with macroscopic topological connectivity. Furthermore, it establishes reliable anchoring channels between graph nodes and the original long text, providing reliable factual anchors for subsequent defense against illusions generated by large models. Simultaneously, relation triples are embedded in the vector space to provide information support for semantic focusing during path expansion.

[0037] 1. Joint extraction of entity relations from corpus physical slicing and automated processing

[0038] For the large-scale unlabeled unstructured text corpus ingested by the system, sliding window segmentation is first performed based on fixed length and overlapping of adjacent parts to generate a standardized text block sequence. As a preferred implementation, the slice length of the sliding window can be set to 512 to 2048 tokens, preferably 1024 tokens, and the overlap ratio between adjacent slices can be set to 10% to 30%, preferably 20%, to ensure that entity relationships are not broken at slice boundaries. Let the original corpus, after segmentation, result in a set of N_d independent text blocks, denoted as:

[0039]

[0040] in, This represents the set of all text slices after physical chunking. Indicates the first A slice of natural language text This indicates the total number of text slices.

[0041] Subsequently, the system concurrently calls the teacher's large language model, taking each independent text block as input. The large language model accurately extracts entities containing key information and action dependencies from complex natural language. Then, it further extracts the relationships between entities. Let the information extraction function be... The teacher's large language model is Then from text slices The set of local entities and the set of local relation triples parsed from the parsed data are represented as follows:

[0042]

[0043]

[0044] in, Indicates a slice of text A local entity set extracted from the data. Indicates a slice of text The set of local relation triples is further extracted based on the already extracted entities. This represents the information extraction operator performed by the large language model. This represents the teacher's large language model.

[0045] The system summarizes and disambiguates the extraction results of all text slices, obtaining a complete set of unique entities and a set of relation triples:

[0046]

[0047]

[0048] in, This represents the global set of entities after entity disambiguation. Indicates the first One entity, Indicates the total number of entities globally; Represents the set of global relation triples. This represents the head entity in the triple. Represents the tail entity in a triple. Indicates the first Relationship, This represents the total number of global relation triples.

[0049] Based on the aforementioned entity set and relation triplet set, the system constructs a globally connected directed knowledge graph in the graph database, denoted as: (Entities are graph nodes, and relation triples are directed graph edges).

[0050]

[0051] in, This represents the constructed global directed knowledge graph. This is a set of graph nodes (corresponding entities). It is a set of directed graph edges (correspondence triples, preserving the directional semantics of the head entity pointing to the tail entity). Through the global connectivity of the knowledge graph, the system can achieve cross-segment information aggregation, thereby effectively breaking the text silo problem that is common in traditional synthesis methods.

[0052] 2. Establishing reverse fine-grained hash tracing pointers between graph nodes and the original text segment.

[0053] Traditional synthesis methods that rely solely on graph topology often discard the original text after graph construction, resulting in the loss of fine-grained context when generating instructions and posing a significant risk of illusion. To fundamentally overcome this deficiency, this invention simultaneously captures the physical slice index of the current text block during entity and relation extraction. In the underlying data structure of the graph, a reverse hash mapping pointer is written for each entity node and relation edge. This pointer strictly and permanently anchors each abstract discrete node or edge in the graph to the original complete text slice position from which that node or edge was initially extracted. The reverse hash tracing mapping function is defined as follows: For entity nodes and relationship edge Their traceability pointers are represented as follows:

[0054]

[0055]

[0056] in, This represents the reverse hash tracing mapping function. Represents entity nodes in the graph. Represents relation edges in a graph. Represents a slice of the original text. Represents the entire set of text slices. This represents the information extraction operator. Representing the teacher's large language model, Indicates from A local entity set extracted from the text. This underlying mapping mechanism ensures that when the system transitions to the generation stage, lossless callbacks of the original long text can be achieved with extremely low overhead.

[0057] 3. High-dimensional dense feature mapping of relation triples

[0058] To enable discrete graph topologies to possess numerical features for semantic similarity calculation within a mathematical space, the system invokes a pre-trained deep text word embedding encoder to perform forward propagation computation on the text representation of each relation triple, generating corresponding high-dimensional dense semantic feature vectors. These continuous semantic vectors are persistently mounted onto the corresponding relation edges in the knowledge graph, completing the transformation from a single pure text modality to a composite underlying structure combining graph topology and a dense feature space. The word embedding mapping operation is defined as follows: The pre-trained text word embedding encoder is For relation triples Its dense feature vector is represented as:

[0059]

[0060] in, Representing relation triples The corresponding high-dimensional dense semantic feature vector, Represents a word embedding mapping function. This represents a pre-trained deep text word embedding encoder. The input relation triples (in the form of text representing head entity, relation, and tail entity) are used as encoder input. As a preferred implementation, the pre-trained text word embedding encoder can use common sentence vector models such as BGE, E5, or Sentence-BERT, and the feature vector dimension can be set to 768 or 1024 dimensions.

[0061] (III) Random truncated path expansion based on hybrid semantic topology mechanism

[0062] This step serves as the core engine for the automatic expansion path of data synthesis in this invention. It aims to actively discover multi-hop complex paths that cover both the diverse macroscopic distribution of the entire domain and have deep implicit logical connections by executing a probability transfer algorithm that balances relevant semantic focus and random divergent exploration on the constructed knowledge graph. This solves the problem of high data homogeneity caused by the reliance on autoregressive probabilities of large models in traditional methods.

[0063] 1. Macro-level unsupervised community clustering and dynamic adaptive seed allocation

[0064] To ensure diversity in the macroscopic perspective of path sampling and avoid the algorithm getting bogged down in the local distribution imbalance of high-frequency popular entities, the system first employs a clustering algorithm based on network modularity optimization at the global level of the knowledge graph. This performs unsupervised partitioning of the graph, automatically generating multiple closely related topic sub-network communities. Since modularity optimization clustering algorithms like Leiden are typically designed for undirected graphs, the system can perform clustering on the associated undirected graph while ignoring edge directions (i.e., symmetric processing of directed edges). The graph topological connectivity of a node is the sum of its in-degree and out-degree. The system then calls the Leiden clustering algorithm to perform clustering on the entire graph. node set Perform the splitting and output the non-overlapping segments. Individual online community:

[0065]

[0066] in, Represents the clustering output A set of non-overlapping community nodes Indicates the first A collection of nodes in a community. Indicates the total number of communities. This represents the Leiden community detection algorithm based on network modularity optimization. This represents the input global knowledge graph, with the constraint that the intersection of the node sets of any two different communities is empty. As a preferred implementation, other community detection algorithms based on modularity optimization, such as Louvain, can also be used.

[0067] After acquiring each independent community, to prevent oversampling of extremely small, long-tail communities or computational overload caused by excessively large mainstream communities, the system introduces a dynamic proportional limiting mechanism to prevent skewness. The system calculates a basic quota based on a certain proportion of the community size, while simultaneously imposing a quota upper limit threshold and setting a minimum guaranteed quota of at least one seed for extremely small communities. This applies to each sub-community. Its adaptive seed quota The calculation is as follows:

[0068]

[0069] in, Indicates the first The number of seed nodes allocated to each community. Indicates the first The total number of nodes in each community This indicates the basic quota percentage (i.e., 5%). This represents the rounding function. Indicates the upper limit threshold of the quota. This indicates a minimum guaranteed quota of 1, ensuring that even very small communities can obtain at least one seed node, thus preventing long-tail communities from being sampled without any seeds.

[0070] The system then concurrently calculates the connectivity (i.e., node degree) of the graph topology for all nodes within each community, sorts them in descending order of connectivity score, and strictly selects locally optimal nodes according to the calculated quota. The selection results from all sub-communities are merged to construct a globally diverse set of initial traversal seeds that represents the core of each domain while effectively avoiding system overload. Global Initial Seed Pool Build as:

[0071]

[0072] in, This indicates the starting seed pool for the global traversal. Indicates the first A seed subset of the community This indicates ranking based on a certain indicator. elements, Represents a node The connectivity of the graph topology. Indicates the first The set of nodes in each community. This expression represents selecting the top nodes in each community in descending order of degree. Each node is used as a seed, and then merged into a global seed pool.

[0073] 2. Multi-hop state aggregation evolution and candidate truncation based on cosine similarity

[0074] Based on the initial seed set extracted in the above steps, multiple traversals are triggered for any starting node in the set. In each evolutionary iteration, the system aggregates the dense feature vectors of all relation edges on the traversed paths in real time through element-wise vector addition, calculating a dynamic state vector that accurately represents the current multi-hop cumulative historical semantics. Let the starting node be... It has now reached the th Step, the recorded path node sequence is as follows The corresponding relation triplet sequence is The current dynamic cumulative state characteristics The calculation is as follows:

[0075]

[0076] in, Indicates wandering to the The dynamic cumulative semantic state vector at each step, Indicates the first path Dense feature vectors of relation triples, This represents the element-wise sum operator, used to fuse the semantic information of each relation edge along a historical path. As a preferred implementation, mean pooling (i.e., summing all feature vectors and dividing by the path length) can also be used. As a state aggregation method, mean pooling and element-wise addition are mathematically equivalent (cosine similarity is not affected by the overall scaling of the vector) under the subsequent cosine similarity measurement, and the two will not produce different technical effects.

[0077] Next, the system scans the current node. For all unvisited outgoing neighbor nodes (since the knowledge graph is a directed graph, only directed outgoing edges originating from the current node are considered here to preserve the directional semantics of the head entity pointing to the tail entity; visited nodes are excluded to ensure that the path is not repeated), the cosine similarity score between the feature vector of the corresponding relation edge of each candidate neighbor node and the above dynamic state vector is calculated. Then, the system first filters out topological noise edges below a set hard relevance threshold to obtain a candidate neighbor set that meets the threshold condition. This set is then sorted in descending order of similarity score, and the top-ranked neighbor nodes are selected, thus constructing a high-quality candidate pool with strong semantic focus locally. Current node Local truncation candidate pool Build as:

[0078]

[0079] in, Indicates the current node Locally truncated candidate neighbor pool, Indicates the current node The set of out-adjacent nodes in a directed knowledge graph (i.e., from...) (The neighboring node pointed to by the directed edge from which the originating edge originates). This represents the sequence of visited path nodes. This represents the set of unvisited outgoing adjacent nodes. Represents the current cumulative state vector Connect the current node and candidate neighbors relation edge feature vector Cosine similarity between them Indicates the hard correlation threshold. This means selecting the top results in descending order of similarity. Each node. The calculation process of this formula is as follows: first, based on the conditions... The candidate set that meets the threshold is obtained through filtering, and then the candidates with the highest similarity are selected from it. One. As a preferred implementation, the cosine similarity threshold... The value range is set to The preferred value is Candidate pool cutoff number The value range is set to The preferred value is The above parameters can be optimized on the development set using grid search based on the actual corpus size and domain characteristics. Fluctuations within the above range have limited impact on the final performance. If the number of neighboring nodes meeting the threshold condition is insufficient... If the number of neighboring nodes that meet the threshold condition is zero, then the current traversal path is terminated.

[0080] 3. Truncation of Uniform Random Sampling within the Candidate Pool and Path Convergence

[0081] Within the high-quality candidate pool generated through the aforementioned rigorous truncation, the system forcibly abandons the greedy search mechanism for absolute maximum values, which typically leads to deterministic repetitive outputs. Instead, it introduces a random sampling algorithm based on discrete uniform distribution to break information homogeneity. The system assigns an absolutely equal transition probability to each node in the pool and randomly determines the actual landing point of the next hop. This mechanism, which introduces structural random perturbations within a controllable high-correlation range, forces the system towards a suboptimal but still highly correlated topological branch that has not been fully explored. Within the already traversed paths... Under the condition, the next hop node Probability of being selected Represented as:

[0082]

[0083] in, Indicates the path already taken Next hop selection node under given conditions The conditional probability, Indicates candidate neighbor nodes, Indicates the current node Local truncation candidate pool, This represents the size of the candidate pool. The formula indicates that each node in the candidate pool has an absolutely equal probability of being selected (uniform distribution), while nodes outside the candidate pool have a zero probability of being selected.

[0084] After selecting the next hop node, the system updates the state to the next step and repeats the above decision-making process of candidate truncation and uniform sampling until the path length triggers the set multi-hop depth limit, or the unvisited neighbor set of the current node is empty, at which point the current random walk process terminates. The above sampling process achieves sampling without replacement by excluding already visited nodes, ensuring that the path does not repeatedly visit the same node. The system summarizes all walk results triggered by the initial seed and merges them to output a structured set of multi-hop candidate logical paths. As a preferred implementation method, the upper limit of multi-hop depth is... The value range is set to The preferred value is This depth is well-suited to the upper limit of the context window for small language models to handle complex causal logic.

[0085] (iv) Cross-textual context reconstruction and multidimensional self-reflection data synthesis

[0086] This step, the final stage of data synthesis in this invention, aims to leverage the powerful instruction compliance and logical evaluation capabilities of the large model to transform the multi-hop topological paths, which combine semantic focus and diverse exploration, discovered in the previous steps into fine-tuning instruction data that can be learned by the small language model. Furthermore, to address the issues of shallow logic and illusions arising from imperfect verification and filtering mechanisms in traditional data synthesis methods, this invention introduces the large language model as an evaluation arbiter. Combined with multi-dimensional, fine-grained inspection signals, the quality of the synthesized fine-tuning instruction data is continuously optimized. This allows the model to not only filter out explicit factual illusions in the synthesized data but also to further uncover hidden and complex logical reasoning relationships, improving the diversity, complexity, and accuracy of the synthesized data. After data synthesis, the small language model uses this data for supervised fine-tuning, achieving simultaneous learning of the teacher's large model's basic reasoning ability and alignment preferences.

[0087] 1. Cross-text physical context splicing

[0088] For any single multi-hop structured path in the extracted multi-hop path set The system first translates the entities and relationships along its path into a causal logical skeleton chain in natural language form. Let the path textification function be... Then the structured path After textualization, a textual representation of the causal logical skeleton chain is obtained. Following this, the system activates the reverse hash tracing mapping channel established during the knowledge foundation construction phase. By passing the path For all nodes and edges on the path, the system batch retrieves and pulls a set of original unstructured physical text block slices that completely correspond to the path from the backend storage, denoted as . For the retrieved set of text slices, the system first performs deduplication (the same slice may be repeatedly retrieved by multiple edges on the path), then sorts and concatenates them according to their order of appearance in the original document. Afterwards, the system enforces cross-text combination on the input side, concatenating the structured logical skeleton text with a macro-level orientation with the unstructured underlying text slices that have rich, realistic, and natural distribution. This creates a cross-text hybrid context. Build as:

[0089]

[0090] in, Indicates a complex context that blends across texts. This represents a string concatenation operation. This indicates a structured multi-hop path. A textualized function that translates into a natural language causal logic skeleton chain. This represents a single multi-hop structured path. This indicates the overwrite path retrieved via a reverse hash pointer. This is a set of original unstructured text slices containing all nodes and edges. This mechanism breaks down the text silos between individual slices, constructing a panoramic hybrid context with a macroscopic cross-document view and microscopic fine-grained context. As a preferred implementation, a clear separator can be added between the structured logical skeleton and the original text slices during splicing to help the large model distinguish between the two information sources; the length of the spliced ​​composite context should be controlled within the upper limit of the context window of the teacher's large model. If it exceeds this limit, the original text slices can be truncated or summarized.

[0091] 2. Joint reasoning generates the initial question and answer.

[0092] The composite context constructed above The code is encapsulated into a customized instruction template and pushed into a large language model for teachers with powerful reasoning capabilities. The large language model is constrained within a mixed context and prompted to aggregate multi-source hidden cues across multiple originally physically isolated text fragments, perform deep multi-step causal deduction, and initially output candidate fine-tuned instruction-question-answer pairs encompassing complex logical reasoning. Let the synthetic data reasoning interface of the large teacher model be... Then the candidate question and answer pair The generation is represented as:

[0093]

[0094] in, This represents the generated candidate question-answer pairs. To indicate a problem, Indicate the answer, This indicates that the teacher's large language model is in complex contexts. Generation probability distribution under conditional constraints, sign This indicates that the question-answer pairs are sampled and generated from this conditional distribution. This formula represents the teacher's large model in a complex context. Under certain constraints, question-answer pairs that require multi-step reasoning are generated.

[0095] 3. Multi-dimensional self-criticism and verification

[0096] After initially generating candidate question-answer pairs, to suppress the inherent tendency of the large model to generate factual illusions, the system immediately triggers a role-switching mechanism in the current context window, transforming the teacher's large language model into an independent and objective evaluator. The system forces the model to conduct in-depth verification of the newly generated candidate pairs from three independent and demanding dimensions according to preset strict inspection criteria.

[0097] The first dimension is a fidelity check, comparing whether the answer is strictly derived solely from the provided mixed context, rigorously checking for the introduction of fabricated statistics from the model's internal parameter memory or the creation of factual illusions. As an operational criterion, if the answer contains entity names, numerical data, or factual statements not present in the context, fidelity is deemed unacceptable. The second dimension is a relevance check, examining whether the intent of the generated question truly covers and utilizes the cross-causal relationships inherent in the input multi-hop paths, strictly preventing the model from adopting a shallow restatement strategy targeting only a specific part of the text. As an operational criterion, if the answer to the question can be directly derived from a single fact corresponding to a single edge in the path, without traversing multi-hop paths for aggregation reasoning, relevance is deemed unacceptable. The third dimension is a completeness check, logically determining whether the generated deductive solution chain has sufficient supporting arguments, and whether the causal chain is self-consistent and closed, strictly avoiding generated data lacking genuine fine-tuning value. As an operational criterion, if the answer only provides a conclusion without providing necessary reasoning steps or supporting arguments, or if there are causal breaks or contradictions in the reasoning chain, completeness is deemed unacceptable.

[0098] Let the comprehensive reflection and evaluation operator be... The evaluation operators for the three dimensions of fidelity, relevance, and integrity are as follows: , , Each dimension returns a Boolean result (true for pass, false for fail), so the comprehensive reflection and evaluation result is represented as a logical AND of the three dimensions:

[0099]

[0100] in, This represents a comprehensive reflection and evaluation operator, which returns a Boolean value (true if all three dimensions pass, false if any dimension fails). This represents a fidelity evaluation operator that checks whether the answer is fully supported by the context and free from illusions. This represents a relevance evaluation operator that checks whether the problem truly utilizes span causality in multi-hop paths; This represents a completeness assessment operator that checks whether the reasoning chain is well-supported and causally consistent. This represents the logical AND operation; This indicates candidate question-answer pairs to be evaluated; This indicates the corresponding cross-textual mixed context. The evaluator, while returning a Boolean decision, also outputs specific criticism text to guide subsequent optimization and rewriting.

[0101] 4. Dynamic discriminative filtering and final data storage on disk

[0102] The large-scale model, acting as the evaluation judge, outputs a comprehensive judgment and modification suggestions based on the verification results across three dimensions. For candidate question-and-answer pairs that pass all three dimensions, the system classifies them as high-quality samples and allows them to proceed. For candidate question-and-answer pairs that fail the checks, the system feeds back the specific criticisms from the evaluation judges to the synthetic data interface. The large-scale model then optimizes and rewrites the question-and-answer pairs based on these criticisms (the large-scale language model performing this optimization and rewriting can be the teacher's large-scale language model itself, or another independently set large-scale language model). The system repeats this closed-loop process of generation and critique until the candidate question-and-answer pair passes all three dimensions or reaches the set maximum number of reflection and modification retries. When the maximum number of retries is reached but the reflection evaluation still fails, the system directly discards the low-quality sample. As a preferred implementation, the maximum number of reflection and modification retries... The preferred value is 3.

[0103] All high-quality samples that pass this quality filtering mechanism are batch-standardized, rewritten, and assembled by the system according to a common small language model fine-tuning standard format. For example, they can adopt Alpaca format (including instruction, input, and output fields) or ShareGPT format (including multi-turn dialogue fields for human and GPT roles). Finally, the data is stored on disk to generate a high-quality fine-tuning instruction dataset that takes into account both diversity and complexity. At this point, the system has completed the fully automated construction of the fine-tuned dataset from the unlabeled corpus. The final fine-tuned dataset is represented as follows:

[0104]

[0105] in, This represents the final high-quality fine-tuning instruction dataset. Indicates the first A fine-tuning instruction Q&A pair that has undergone quality purification. Indicates the first One question, Indicates the first Answer 1 This represents the total number of question-answer pairs in the final dataset.

[0106] 5. Instruction Template

[0107] To enable those skilled in the art to clearly understand and reproduce the above data synthesis and self-criticism process, the following provides instruction templates for the three core steps as preferred implementation methods.

[0108] First, the data synthesis template. This template guides teachers' large language models in generating multi-hop reasoning questions and answers based on knowledge subgraph paths and original context. The template content is as follows:

[0109] "You are an expert question-answering generator. Please generate multi-hop reasoning questions and answers based on the following knowledge subgraph path and original context. You will be given a knowledge subgraph path and the original source context. Your task is to formulate a question that requires multiple steps of reasoning to answer. The answer to the question should be inferred from the given knowledge subgraph and supported by the original context. Ensure that the question is of moderate difficulty, requiring multiple steps of reasoning to answer."

[0110] Example:

[0111] --Knowledge Path--

[0112] 1. Apple -- [is a type of] --> fruit

[0113] 2. Fruits -- [Rich in] --> Vitamin C

[0114] --Original Context--

[0115] Apples are a popular fruit. Most fruits, including apples, are rich in vitamin C, which is good for health.

[0116] Question: What substances do you get from eating apples that help maintain your health?

[0117] Answer: Vitamin C

[0118] In actual use, replace the knowledge path and original context in the above example with the variables {path_text} and {context_text} respectively, and require the model to directly output a JSON object containing the question and answer fields.

[0119] Second, the three-dimensional reflection and evaluation template. This template is used to switch the teacher's large language model into an evaluation judge, checking candidate question-and-answer pairs in three dimensions: fidelity, relevance, and completeness. The template content is as follows:

[0120] "You are a rigorous critic. Evaluate the provided question-and-answer pair based on the context. Check: 1. Illusion: Is the answer fully supported by the context? 2. Relevance: Does the question make sense considering the path? 3. Completeness: Is the answer complete? Return JSON containing is_valid (boolean) and critical (string interpretation)."

[0121] When actually calling the template, the original context {context_text}, knowledge path {path_text}, question {question}, and answer {answer} are filled in. The model is required to output the is_valid field (true if all three dimensions pass, false if any dimension fails) and the criticy field (detailed explanation of the problems and modification suggestions).

[0122] Third, the synthetic data optimization template. This template is used to provide feedback to the synthetic model when the reflective evaluation determines that a candidate question-answer pair fails, guiding it to optimize and rewrite the model. The template content is as follows:

[0123] "You are an expert question-answer optimizer. Improve the question-answer pairs based on feedback. Context: {context_text}. Original question and answer: Question: {question}, Answer: {answer}. Criticism: {critique_text}. Generate an optimized JSON containing the question and answer."

[0124] In actual use, the original context, the original question-and-answer pair, and the criticisms from the reflection and evaluation output are filled into the corresponding variables. The model is then required to generate optimized question-and-answer pairs based on the criticisms. The optimized question-and-answer pairs are then sent back to the three-dimensional reflection and evaluation template for review until they pass or the maximum number of retries is reached.

[0125] (V) System Implementation Examples

[0126] Based on the same inventive concept, this embodiment also provides a large model fine-tuning data synthesis system based on graph retrieval enhancement. The system includes a knowledge graph construction module, a path expansion module, a data synthesis module, and a quality assessment module. The modules work together to implement all the steps in the above method embodiment.

[0127] The knowledge graph construction module divides the input text corpus into multiple text slices, extracts entities and relationships between entities from each slice, and constructs a globally connected knowledge graph with entities as nodes and relationships as directed edges. It establishes reverse hash tracing pointers for each node and edge, pointing to its source text slice, and persistently mounts the text representations of each relationship edge as semantic feature vectors to the corresponding relationship edges. The knowledge graph, reverse hash tracing pointers, and semantic feature vectors of the relationship edges output by this module together form the input foundation for subsequent modules.

[0128] The path expansion module, connected to the knowledge graph construction module, receives the completed knowledge graph, divides the knowledge graph into communities, determines the starting node quota according to the size of each community, selects starting nodes, performs a hybrid semantic topology truncation random walk from each starting node, aggregates the semantic feature vectors of each relation edge on the walked path in each step of the walk to obtain a cumulative semantic state vector, performs threshold filtering and number truncation of candidate neighbors with cosine similarity, and uniformly randomly samples in the candidate pool to determine the next hop node, and finally generates a multi-hop path set that combines semantic focus and diverse exploration.

[0129] The data synthesis module, connected to the path expansion module and the knowledge graph construction module, is used to retrieve the original text slices corresponding to each node and edge on each multi-hop path through the reverse hash tracing pointer established by the knowledge graph construction module. The path is then translated into a causal logic skeleton chain in text form, which is concatenated with the retrieved original text slices to form a composite context. The composite context is then input into the teacher's big language model to generate candidate question-answer pairs.

[0130] The quality assessment module, connected to the data synthesis module, is used to input candidate question-answer pairs and their complex contexts into the evaluation large language model. It evaluates the candidate question-answer pairs from three dimensions: fidelity, relevance, and completeness. Only when all three dimensions pass is the candidate question-answer pair included in the fine-tuning dataset. Preferably, the quality assessment module also outputs criticisms when the evaluation fails, feeding these criticisms back to the data synthesis module to drive the optimization and rewriting of the question-answer pairs, forming a closed loop of generation—evaluation—optimization—re-evaluation, until the question-answer pair passes the evaluation or reaches the preset maximum number of retries, at which point it is discarded.

[0131] The above modules can be integrated into the same electronic device or deployed in different electronic devices to work together according to their functions; the specific operations performed by each module are consistent with the corresponding steps in the above method embodiments, and will not be repeated here.

[0132] (vi) Experimental verification

[0133] 1. Experimental baseline and dataset setup

[0134] To verify the technical effectiveness of this invention, quantitative verification was conducted on four open-source datasets with significantly different scenarios: SeedBench (agricultural seed professional scenario), Qasper (large language model academic paper scenario), PubMedQA (medical professional diagnosis scenario), and MCTest (open life story scenario). To verify the superiority of this invention, six traditional synthetic data methods were selected as baselines for comparison, including four methods based solely on text block extraction: Genie (directly extracting instructions from text blocks using prompts), Wrap (dynamically extracting different numbers of instructions based on different text blocks based on Genie), Self-QA (extracting questions from text blocks first, then generating answers), and LongForm (the opposite of Self-QA, using a text segment as the answer first, then generating corresponding questions in reverse order). Additionally, two baselines based solely on knowledge graph topology were compared: EntiGraph (extracting triples and directly generating questions related to the triples) and GraphGen (building a knowledge graph and generating questions based on model confidence evaluation and subgraph extraction). All baselines used Qwen2.5-72B-Instruct as the teacher model to synthesize fine-tuning instructions. The method of this invention also uses this model as the teacher model to ensure the fairness of the comparison.

[0135] 2. Analysis of the complexity and diversity of synthetic data

[0136] Before fine-tuning, a large language model (Qwen2.5-72B-Instruct) is used to evaluate whether the instructions synthesized from each baseline have fine-tuning value (i.e., complexity). Instruction quality is divided into three levels: Score 1 represents instructions with no training value, Score 2 represents instructions of low quality, and Score 3 represents effective instructions with fine-tuning value. For example... Figure 2 As shown in the table below, the quality level distribution of the synthesis instructions for each method is as follows:

[0137]

[0138] Experimental data shows that the data synthesized in this invention has a significant advantage in terms of instruction complexity. Instructions with fine-tuning value (Score 3) account for 96%, and instructions with no training value (Score 1) are completely filtered out through the reflection mechanism. It should be noted that the statistics in the table above refer to the final dataset after reflection filtering. The remaining approximately 4% of lower-quality instructions (Score 2) are due to discrepancies in judgment between the evaluation model and the reflection judge on boundary samples, and do not affect the overall high quality of the dataset.

[0139] To further quantify the diversity of the synthetic data, a Quality Reward Diversity (QRD) score is calculated based on the quality score and lexical diversity of each instruction. The formula for calculating the QRD metric is as follows:

[0140]

[0141] in, This indicates the diversity score for quality rewards. This represents the overall quality score of the large model for instruction-response pairs (with values ​​of 1, 2, and 3). For the normalized offset, such that hour (Based on medium quality as zero). When a negative score is received, A positive score reward is awarded at that time; It stands for Measure of Textual Lexical Diversity, which measures the lexical richness of a text. Used to prevent Logarithmic operations are meaningless at this time; This represents the natural logarithm transformation, used to suppress the upward shift of the mean by extreme large values, thus avoiding statistical bias caused by a few extremely long texts in real corpora.

[0142] The QRD scores of each method on the four datasets are shown in the table below:

[0143]

[0144] In terms of QRD diversity score, the average score of the synthesized data in this invention reached the highest at 3.63, significantly higher than Genie (3.43) and Self-QA (3.41). Especially in open scenarios like MCTest, which easily induce the illusion of large model divergence, traditional text-based methods (such as Wrap) are penalized to only 1.21 points due to generating a large amount of meaningless nonsense, while this invention still maintains a stable score of 3.18. This quantitatively demonstrates that the hybrid random walk and reflection mechanism of this invention effectively breaks the information homogenization of traditional synthesis methods and effectively filters out factual illusions and shallow logical data in complex scenarios, resulting in data with a clear advantage in both complexity and effectiveness.

[0145] 3. Analysis of the improvement in downstream model fine-tuning capability

[0146] To verify the actual gains of the high-quality data on the small language model, the same fine-tuning strategy was used consistently. Fine-tuning was performed on the Qwen2.5-7B-Instruct student model using synthetic data from each baseline, with Bleu-4 and Rouge-L used as quantization inference metrics. All fine-tuning was performed within the LLaMA-Factory 0.9.4 dev framework, using a unified fine-tuning configuration as follows: the fine-tuning method was full-parameter fine-tuning, with a learning rate set to 2×10⁻⁶. -5 The batch size per device was set to 16, the gradient accumulation step count to 2, the number of training epochs to 2, the maximum sequence length to 2048, the learning rate scheduler to cosine, the warm-up ratio to 0.03, the computational precision to bfloat16, the attention mechanism to FlashAttention-2, and the distributed training to DeepSpeed ​​ZeRO-3. Equal amounts of synthetic samples were used for fine-tuning across datasets to ensure fairness in comparisons. Furthermore, the MTLD lexical diversity measure in the QRD metric was calculated using the complete text concatenated from the instruction and response, employing the standard MTLD algorithm (default word frequency threshold of 0.72). The performance of the small models driven by each method for fine-tuning on the four datasets is shown in the table below:

[0147]

[0148] Experimental results show that the small model driven by this invention achieves a leading position in the overall average score across four scenarios: Bleu-4 reaches 27.43, and Rouge-L reaches 28.66. Specifically, Bleu-4 achieves a relative performance improvement of approximately 11.8% compared to the second-place Genie (24.54), and Rouge-L achieves a relative performance improvement of approximately 10.6% compared to the second-place GraphGen (25.91). It should be noted that on individual datasets, a particular metric of this invention may be slightly lower than or equal to a certain baseline. For example, on the PubMedQA dataset, Bleu-4 (28.56) is slightly lower than EntiGraph (30.94); on the Qasper dataset, Bleu-4 (15.39) is slightly lower than Wrap (15.94) and EntiGraph (15.85); and on the MCTest dataset, Rouge-L (12.82) is equal to GraphGen. This is because scenarios like PubMedQA and Qasper contain many questions that can be answered simply by extracting facts from a single document. The cross-document multi-hop path extension mechanism of this invention may introduce a small amount of irrelevant information into these single-hop factual questions, leading to slight fluctuations in the Bleu-4 metric. However, the advantages of this invention are more pronounced in complex questions requiring cross-document aggregation reasoning, and it leads in both the overall average dimensionality and the Rouge-L average dimensionality across the four datasets. Furthermore, in terms of QRD diversity, this invention scores slightly lower than Genie (3.69) on the SeedBench dataset (3.60), but leads in the other three datasets and the overall average. This does not negate the overall technical effectiveness of this invention; rather, it demonstrates its more significant advantages in complex multi-hop reasoning scenarios. This proves that this invention can successfully transfer the higher-order capabilities of the teacher model to the student model, achieving efficient knowledge distillation.

[0149] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.

Claims

1. A method for fine-tuning data synthesis of a large language model based on graph retrieval enhancement, characterized in that, include: The text corpus is divided into multiple text slices. Entities and relationships between entities are extracted from each text slice. A knowledge graph is constructed with entities as nodes and relationships as directed edges. A reverse hash tracing pointer is established for each node and edge, pointing to its source text slice. Each relationship edge is mapped to a semantic feature vector. Performing a hybrid semantic topological truncation random walk on the knowledge graph to generate a multi-hop path set includes: dividing the knowledge graph into communities, determining the starting node quota for each community according to the size of each community, and selecting a starting node in the corresponding community according to the quota; starting from each starting node, aggregating the semantic feature vectors of each relation edge on the already walked path in each step of the walk to obtain a cumulative semantic state vector, calculating the cosine similarity between the feature vector of each candidate neighbor relation edge and the cumulative semantic state vector, eliminating neighbor nodes that do not meet the preset similarity threshold, selecting a preset number of nodes in descending order of similarity to form a candidate pool, uniformly and randomly sampling in the candidate pool to determine the next hop node and not repeatedly visiting the already visited nodes on the same path, until the preset depth limit is reached or there are no unvisited neighbor nodes that meet the preset similarity threshold, and then terminating. For each multi-hop path, the original text slices corresponding to each node and edge on the path are pulled by the reverse hash tracing pointer. The path is translated into a skeleton chain in text form and concatenated with the pulled original text slices to form a composite context. Input the complex context into the teacher's large language model to generate candidate question-answer pairs; The candidate question-answer pairs and their complex contexts are input into the evaluation of the large language model, which is evaluated from three dimensions: fidelity, relevance, and completeness. Only those that pass all three dimensions are included in the fine-tuning dataset.

2. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The community division of the knowledge graph adopts the Leiden algorithm or the Louvain algorithm; the determination of the starting node quota of each community according to the size of each community includes: for each community, its starting node quota is calculated as 5% of the number of nodes in the community and rounded down, and is not less than 1 and not greater than 10; from each community, nodes with the same number of starting nodes as the community’s starting node quota are selected in descending order of node degree.

3. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The step of mapping each relation edge to a semantic feature vector includes: inputting the text of the relation triple corresponding to the relation edge into a pre-trained word embedding encoder to obtain a semantic feature vector, wherein the pre-trained word embedding encoder includes BGE, E5 or Sentence-BERT, and the dimension of the semantic feature vector is 768 or 1024; the step of aggregating the semantic feature vectors of each relation edge on the already visited path includes: adding the semantic feature vectors of each relation edge on the already visited path element by element to obtain a cumulative semantic state vector, or performing mean pooling on the semantic feature vectors of each relation edge on the already visited path to obtain a cumulative semantic state vector.

4. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The preset similarity threshold ranges from 0.5 to 0.85; the preset number ranges from 5 to 15; when the number of neighbor nodes that meet the preset similarity threshold is less than the preset number, all neighbor nodes that meet the condition are selected to form a candidate pool; the preset depth upper limit ranges from 3 to 6.

5. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The process of translating the path into a text-based skeleton chain and concatenating it with the retrieved original text slices to form a composite context includes: translating entities and relationships along the multi-hop path into causal logic skeleton chain text; deduplicating the retrieved original text slices and sorting them according to their order of appearance in the original document; concatenating the causal logic skeleton chain text with the sorted original text slices using a preset delimiter to form a composite context; and truncating or summarizing the original text slices when the length of the composite context exceeds the preset context window limit.

6. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The evaluation from the three dimensions of fidelity, relevance, and completeness includes: fidelity dimension checking whether the facts in the answer are fully supported by the composite context; if the answer contains entities, values, or factual statements that do not exist in the composite context, fidelity is deemed unsatisfactory; relevance dimension checking whether the question covers and utilizes the causal relationships implied in the multi-hop path; if the answer can be directly derived from a single fact corresponding to a single edge in the multi-hop path, relevance is deemed unsatisfactory; and completeness dimension checking whether the reasoning chain of the answer is sufficiently supported and causally consistent; if the answer only gives a conclusion without providing reasoning steps or supporting arguments, or if the reasoning chain has causal breaks or contradictions, completeness is deemed unsatisfactory.

7. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: When a candidate question-answer pair fails the three-dimensional evaluation, the evaluation big language model outputs criticisms. The criticisms, along with the composite context and the candidate question-answer pair, are then input into the optimization big language model to generate an optimized question-answer pair. The generation of the optimized question-answer pair is executed using a preset optimization instruction template, which includes context variables, original question-answer variables, and criticism variables. The template requires the model to output optimized structured data containing questions and answers based on the criticisms. The optimized question-answer pair will be evaluated again in three dimensions until the evaluation or optimization retries reach the preset maximum number of retries; if the maximum number of retries is reached and the candidate question-answer pair still fails, it will be discarded.

8. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The assessment language model uses a pre-set three-dimensional reflection assessment instruction template. The template requires the model to output structured data containing three-dimensional assessment judgment results and criticisms. The judgment result is "pass" indicating that all three dimensions of fidelity, relevance, and completeness have been passed. The criticisms are used to explain the existing problems and suggestions for improvement. The teacher language model uses a pre-set data synthesis instruction template. The template includes knowledge path variables and original context variables, and requires the model to output structured data containing questions and answers.

9. The method for fine-tuning large language model data synthesis based on graph retrieval enhancement according to claim 1, characterized in that: The text corpus is divided into multiple text slices using a sliding window method, with slice lengths ranging from 512 to 2048 tokens and overlap ratios between adjacent slices ranging from 10% to 30%. The extraction of entities and relationships between entities from each text slice is performed by concurrently calling a large language model, and entity disambiguation is performed on the extraction results.

10. A data synthesis system for fine-tuning large language models based on graph retrieval enhancement, characterized in that, include: The knowledge graph construction module is used to divide the text corpus into multiple text slices, extract entities and relationships between entities from each text slice, construct a knowledge graph with entities as nodes and relationships as directed edges, establish reverse hash tracing pointers for each node and edge pointing to its source text slice, and map each relationship edge to a semantic feature vector. The path expansion module is used to divide the knowledge graph into communities and select starting nodes, and perform a hybrid semantic topology truncation random walk from each starting node to generate a multi-hop path set; The data synthesis module is used to pull the original text slices corresponding to each node and edge on each multi-hop path through the reverse hash tracing pointer, translate the path into a skeleton chain in text form, and concatenate it with the pulled original text slices to form a composite context. The composite context is then input into the teacher's big language model to generate candidate question-answer pairs. The quality assessment module is used to input candidate question-answer pairs and their complex contexts into the large language model for evaluation. It evaluates the model from three dimensions: fidelity, relevance, and completeness. Only when all three dimensions pass the evaluation will the model be included in the fine-tuning dataset.