Knowledge graph generation method and system based on RAG deduction

By generating task structure templates, performing dense retrieval and coverage analysis in the RAG method, and dynamically optimizing the text set, the problem of fusion context is solved, a high-quality knowledge graph is generated, and the accuracy and completeness of triples are ensured.

CN120633809BActive Publication Date: 2025-11-18DONGHUA SOFTWARE INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510788685.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-13
Publication Date
2025-11-18
Estimated Expiration
2045-06-13

AI Technical Summary

Technical Problem

Existing RAG methods fail to effectively identify and correct problems in the fusion context during knowledge graph generation, resulting in entity errors, relation mismatches, or attribute omissions in the generated triples. This is especially true in complex, multi-source heterogeneous text contexts, affecting the accuracy and usability of the knowledge graph.

Method used

By extracting the expected entity categories, relation categories, and domain context from the task, a task structure template is generated. A dense retrieval method is used to initially retrieve the candidate text set, perform entity and relation coverage analysis, identify areas with missing coverage, dynamically construct supplementary retrieval queries, optimize the text set, and calculate the fusion quality failure coefficient until a high-quality structured triple set is generated.

Benefits of technology

This ensures that problems in the fusion context can be identified and corrected in a timely manner, reduces the occurrence of errors or omissions in the generated triples, and improves the accuracy and usability of the knowledge graph.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120633809B_ABST
    Figure CN120633809B_ABST
Patent Text Reader

Abstract

The application discloses a knowledge graph generation method and system based on RAG deduction, relates to the technical field of knowledge graph generation, and extracts expected entity categories, relation categories and domain contexts in a knowledge graph generation task, constructs a task structure template, and performs dense retrieval in combination with keywords to obtain a preliminary candidate text set. Subsequently, entity and relation coverage is analyzed, missing information is identified and supplementary retrieval is performed, and the text set is optimized. The text set is fused and state information is obtained, a fusion quality unqualified coefficient is calculated, if the coefficient is less than a threshold value, a structured triple set is generated based on a fusion context vector; otherwise, fusion is performed again until generation is completed. The method can effectively detect the fusion mechanism process, identify and correct potential problems in a timely manner, reduce the risk of entity errors, relation mismatches and the like in knowledge graph generation, and improve the accuracy and usability of the knowledge graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge graph generation technology, specifically to a knowledge graph generation method and system based on RAG deduction. Background Technology

[0002] With the development of natural language processing and knowledge graph technologies, Retrieval-Augmented Generation (RAG) has gradually become the mainstream technology for automatic knowledge graph construction. RAG methods, by combining external knowledge base retrieval with language generation models, can generate richer and more accurate knowledge triples. Specifically, RAG methods typically follow a "retrieval-fusion-generation" process in knowledge graph generation: First, based on the user's input question or task, relevant content fragments are retrieved from large-scale text corpora or knowledge documents; then, these retrieval results are encoded together with the original input, incorporating contextual knowledge through fusion mechanisms (such as cross-attention or concatenation); finally, a language generation model is used to understand and organize the fused information, outputting structured triples containing entities, relations, and attributes, thus generating a knowledge graph. This process combines knowledge recall with language understanding capabilities, improving both the scope of knowledge coverage and the accuracy and diversity of generated content, thereby providing effective support for knowledge graph construction in complex scenarios.

[0003] However, existing RAG methods generally assume that the fusion mechanism will not encounter problems during the fusion process and directly generate knowledge graphs based on the fusion results. This may lead to problems in the fusion context that cannot be identified and corrected in a timely manner, resulting in entity errors, mismatched relations, or missing attributes in the generated triples. This seriously affects the accuracy and usability of the knowledge graph, especially in complex, multi-source, and heterogeneous text contexts, where this problem is even more prominent. Summary of the Invention

[0004] The purpose of this invention is to solve the problems mentioned above and to provide a method and system for generating knowledge graphs based on RAG deduction.

[0005] In a first aspect of this invention, a knowledge graph generation method based on RAG deduction is first proposed, the method comprising:

[0006] For the input knowledge graph generation task, the expected entity categories, relation categories and domain context are extracted from the task to generate a task structure template, which serves as a target guide for subsequent retrieval and generation.

[0007] Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set;

[0008] Entity and relation coverage analysis is performed on the candidate text set to identify the missing coverage areas, and supplementary search queries are dynamically constructed based on the missing information to optimize and improve the text set.

[0009] The text set is fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, knowledge graph generation is performed based on the fusion context vector, and the output is a structured triple set containing entities, relations and attributes.

[0010] If the failure rate of the fusion quality is not less than the threshold, the text set will be fused again until the knowledge graph is generated.

[0011] Optionally, based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set, including the following steps:

[0012] The expected entity category, relation category, and domain context information are converted into text descriptions; a pre-trained language model is used to encode the text descriptions into dense vectors. Based on the input keywords for the specific task, a dense keyword vector is generated. ;

[0013] right and Perform weighted fusion to obtain the final fusion vector. ;

[0014] All text fragments in the candidate text library are pre-encoded into a set of vectors. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ;

[0015] Cosine similarity Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

[0016] Optionally, the steps to perform supplementary searches to optimize and improve the text collection are as follows:

[0017] Using entity recognition and relation extraction techniques, the entity type and relation type contained in each candidate text in the candidate text set are extracted, and the entity set and relation set extracted from all texts are compared with the expected entity category and relation category set in the task structure template.

[0018] Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relation set and the expected relation category, and add the two ratios to obtain the structure coverage index;

[0019] When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text set. After identifying the missing entity categories or relationship categories, a supplementary retrieval query is constructed based on the missing information to optimize and improve the text set.

[0020] Optionally, the steps of fusing the text sets and obtaining the state information during the fusion process to calculate the fusion quality failure coefficient are as follows:

[0021] The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized to remove units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

[0022] Optionally, the calculation steps for the attention weight dispersion coefficient and the semantic consistency deviation coefficient are as follows:

[0023] Let the text set be After fusion using the attention mechanism, the attention weight distribution for each text is obtained. ,in, , ;

[0024] Calculate the entropy of the attention distribution , , Minimal positive numbers, avoid ;

[0025] Entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient;

[0026] Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model. These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ;

[0027] Calculate the vector of each fragment With overall context vector similarity between , ;

[0028] Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.

[0029] In a second aspect of the invention, a knowledge graph generation system based on RAG deduction is proposed, the system comprising:

[0030] The retrieval module extracts the expected entity categories, relationship categories, and domain context from the input knowledge graph generation task, and generates a task structure template as a target guide for subsequent retrieval and generation.

[0031] Preliminary text module: Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set;

[0032] Optimize text module: Perform entity and relation coverage analysis on the candidate text set, identify the missing coverage areas, dynamically construct supplementary search queries based on the missing information, and execute supplementary searches to optimize and improve the text set;

[0033] Evaluation module: It fuses the text set and obtains the state information during the fusion process to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, it performs knowledge graph generation based on the fusion context vector and outputs a structured triple set containing entities, relations and attributes.

[0034] Knowledge graph generation module: If the fusion quality failure coefficient is not less than the threshold, the text set will be fused again until the knowledge graph is generated.

[0035] Optionally, the preliminary text module includes:

[0036] Vector encoding module: Converts expected entity categories, relation categories, and domain context information into text descriptions; uses a pre-trained language model to encode the text descriptions into dense vectors. Based on the input keywords for the specific task, a dense keyword vector is generated. ;

[0037] Fusion Vector Module: For and Perform weighted fusion to obtain the final fusion vector. ;

[0038] Cosine similarity calculation module: pre-encodes all text fragments in the candidate text library into a vector set. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ;

[0039] Candidate text set module: This module uses cosine similarity. Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

[0040] Optionally, the optimized text module includes:

[0041] Extraction module: Utilizing entity recognition and relation extraction technologies, it extracts the entity types and relation types contained in each candidate text from the candidate text set, and compares the entity sets and relation sets extracted from all texts with the expected entity categories and relation categories set in the task structure template.

[0042] Coverage module: Calculates the ratio between all categories in the entity set and the expected entity category, calculates the ratio between all categories in the relationship set and the expected relationship category, and adds the two ratios to obtain the structure coverage index;

[0043] Text Collection Module: When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text collection; after identifying the missing entity categories or relationship categories, a supplementary search query is constructed based on the missing information to optimize and improve the text collection.

[0044] Optionally, the evaluation module includes a fusion quality non-compliance coefficient calculation module, which includes:

[0045] The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized to remove units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

[0046] Optionally, the evaluation module further includes:

[0047] Weight distribution module: Let the text set be... After fusion using the attention mechanism, the attention weight distribution for each text is obtained. ,in, , ;

[0048] Entropy calculation module: Calculates the entropy of the attention distribution. , , Minimal positive numbers, avoid ;

[0049] Attention weight distribution module: This module distributes the entropy of attention weights. Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient;

[0050] Vector setting gate module: Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model. These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ;

[0051] Similarity calculation module: calculates the vector for each fragment. With overall context vector similarity between , ;

[0052] Semantic consistency deviation module: calculates all similarities The standard deviation is used as the semantic consistency deviation coefficient.

[0053] The beneficial effects of this invention are:

[0054] This invention proposes a knowledge graph generation method and system based on RAG inference. For an input knowledge graph generation task, it extracts the expected entity categories, relation categories, and domain context to generate a task structure template, serving as a target guide for subsequent retrieval and generation. Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve a candidate text set. Entity and relation coverage analysis is performed on the candidate text set to identify missing coverage areas. Supplementary retrieval queries are dynamically constructed based on the missing information, and supplementary retrieval is executed to optimize and improve the text set. The text set is then fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than a set threshold, knowledge graph generation is performed based on the fusion context vector, outputting a structured set of triples containing entities, relations, and attributes. If the fusion quality failure coefficient is not less than the threshold, the text set is fused again until the knowledge graph generation is complete. This allows for the detection of the fusion mechanism and process, enabling the generation of a knowledge graph based on the fusion result. Problems in the integrated context can be identified and corrected in a timely manner, and the generated triples are less likely to have entity errors, relationship mismatches, or attribute omissions, thus ensuring the accuracy and usability of the knowledge graph. Attached Figure Description

[0055] The invention will now be further described with reference to the accompanying drawings.

[0056] Figure 1 This is a flowchart of a knowledge graph generation method based on RAG inference;

[0057] Figure 2 This is a framework diagram of a knowledge graph generation system based on RAG inference. Detailed Implementation

[0058] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0059] This invention provides a method for generating knowledge graphs based on RAG deduction. See also... Figure 1 , Figure 1 A flowchart illustrating a knowledge graph generation method based on RAG inference provided in an embodiment of the present invention. The method includes the following steps:

[0060] For the input knowledge graph generation task, the expected entity categories, relation categories and domain context are extracted from the task to generate a task structure template, which serves as a target guide for subsequent retrieval and generation.

[0061] Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set;

[0062] Entity and relation coverage analysis is performed on the candidate text set to identify the missing coverage areas. Supplementary search queries are dynamically constructed based on the missing information, and supplementary searches are performed to optimize and improve the text set.

[0063] The text set is fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, knowledge graph generation is performed based on the fusion context vector, and the output is a structured triple set containing entities, relations and attributes.

[0064] If the failure rate of the fusion quality is not less than the threshold, the text set will be fused again until the knowledge graph is generated.

[0065] Based on the RAG-based knowledge graph generation method provided in this invention, the fusion process of the fusion mechanism can be detected through the above-described method, enabling the generation of a knowledge graph based on the fusion result. Problems in the fusion context can be identified and corrected in a timely manner, and the possibility of entity errors, relation mismatches, or attribute omissions in the generated triples is relatively small, ensuring the accuracy and usability of the knowledge graph.

[0066] In one embodiment, for the input knowledge graph generation task, the expected entity categories, relationship categories and domain context in the task are extracted to generate a task structure template, which serves as a target guide for subsequent retrieval and generation.

[0067] It should be noted that in the process of extracting expected entity categories, relation categories, and domain context from the input knowledge graph generation task, and generating a task structure template, the core objective is to transform the task intent described in natural language into a structured "expectation graph framework" as a guiding basis for subsequent retrieval and generation. This process typically includes four key steps: task semantic parsing, domain background recognition, structural element extraction, and structural template construction.

[0068] First, the system receives task input from the user or higher layers. This input may be a natural language question, description, text, or query instruction. A semantic parsing module (such as a Transformer-based semantic role labeler or named entity recognizer) analyzes the task text to identify key entity fragments (such as proper nouns, organizations, people, and locations) and candidate relational verbs or phrases (such as "belongs to," "serves," "is located in," and "involves in"). Simultaneously, a pre-trained language model and domain dictionary are used to perform contextual modeling of the input text, thereby identifying the task's domain (such as law, medicine, finance, etc.) to determine the domain knowledge boundaries and background preferences involved in the task.

[0069] Next, based on the identified entities and relationships, and in accordance with knowledge graph construction specifications (such as whether it is triple-oriented construction, whether attribute information is required, etc.), a preliminary structural target framework is constructed. This framework is not a complete knowledge graph, but a structural sketch expected by the task, containing several expected triple placeholder structures. Each structure may be represented as (entity type 1, placeholder relationship, entity type 2), and uncertain areas can be labeled.

[0070] Suppose the input knowledge graph generation task is: "Please construct a knowledge graph about 'Alzheimer's disease treatment plans'." First, semantic parsing is performed on this input. Using a named entity recognition model, "Alzheimer's disease" is identified as the core medical disease entity. Simultaneously, "treatment plan" implies multiple related medical entity categories, such as "drug name," "treatment method," "research institution," and "side effects." Next, a relation extraction model is used to perform semantic matching with a medical knowledge ontology, identifying potential important relation types in the task, including "treated (drug_treats)," "researched by (researched_by)," and "has side effects (has_side_effect)." At the same time, by analyzing the similarity between task keywords and domain tags in the knowledge base, the task domain is determined to belong to the "neuromedicine / disease treatment" category, and specific terminology and structural preferences for this domain are loaded. After integrating the above information, the following task structure template is constructed:

[0071] Entity categories: Disease (Alzheimer's disease), Drug, Treatment method, Research institution, Side effects;

[0072] Relationship type: treated, researched, side effects, indications;

[0073] Domain context: neurodegenerative diseases, geriatrics, clinical treatment.

[0074] In one implementation, the task structure template not only clearly defines the types of entities and relationships that should be covered in subsequent retrieval and generation, but also provides semantic constraints for the contextual domain in the generation stage, making the final generated knowledge graph more in line with the task intent and more logically structured and application-valued.

[0075] In one embodiment, S2: Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set, including the following steps:

[0076] Convert the expected entity categories, relationship categories, and domain context information into text descriptions; such as "contains disease entities, drug entities, and 'treatment' relationships";

[0077] Text descriptions are encoded into dense vectors using pre-trained language models (such as BERT, SimCSE, etc.). Combine specific task-specific input keywords (such as "Alzheimer's disease", "medication", "treatment") to generate a keyword-dense vector. ;

[0078] right and Perform weighted fusion to obtain the final fusion vector. ;

[0079] All text fragments in the candidate text library are pre-encoded into a set of vectors. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ;

[0080] Cosine similarity Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

[0081] It should be noted that, taking "drug treatment for Alzheimer's disease" as an example for knowledge graph generation, the expected structural objectives are first extracted from the task. These objectives include elements such as "disease entity (Alzheimer's disease)," "drug entity," "treatment relationship," and related "mechanism of action" and "clinical trial data." These structural requirements are then converted into structural description text: "The text should contain the names of drugs related to Alzheimer's disease, treatment relationships, and their mechanisms of action." Simultaneously, the user's task input includes keywords: "Alzheimer's disease," "treatment," and "drug." Using a pre-trained language model such as SimCSE, the structural description and task keywords are encoded separately, resulting in two dense semantic vectors. These are then fused into a unified fusion query vector according to preset weights (e.g., 0.6 for the structural vector and 0.4 for the keyword vector). Subsequently, all pre-encoded text fragment vectors are retrieved from a large medical text database, and their cosine similarity is calculated with the fusion vector. Segments with a similarity of at least 0.75 are selected as the candidate text set. For example, the text segment "Donepezil is a commonly used drug for treating Alzheimer's disease, which improves cognitive function by inhibiting acetylcholinesterase" was identified as a highly matched text because it simultaneously contains disease entities, drug entities, and treatment relationships, and was therefore included in the candidate set; while segments unrelated to the task structure, such as "diabetic patients should pay attention to dietary control," were excluded. Through this process, a preliminary set of texts with high structural relevance was constructed, laying the foundation for subsequent structural coverage analysis and map generation.

[0082] In one embodiment, S3: Perform entity and relation coverage analysis on the candidate text set, identify the missing coverage areas, dynamically construct supplementary search queries based on the missing information, and execute supplementary searches to optimize and improve the text set.

[0083] Using entity recognition and relation extraction techniques, the entity type and relation type contained in each candidate text in the candidate text set are extracted, and the entity set and relation set extracted from all texts are compared with the expected entity category and relation category set in the task structure template.

[0084] Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relation set and the expected relation category, and add the two ratios to obtain the structure coverage index;

[0085] When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text set. After identifying the missing entity categories or relationship categories, a supplementary retrieval query is constructed based on the missing information to optimize and improve the text set.

[0086] This query transforms missing structural elements into textual supplementary descriptive information and constructs a semantically complete extended query description by combining task context keywords. A semantic encoding model is then used to convert this into a dense vector representation, enabling targeted dense retrieval to obtain text fragments highly relevant to the missing structure. Subsequently, the supplementary retrieved text fragments are incorporated into the original candidate set, forming a text set with higher structural coverage. This ensures that the subsequent fusion and generation process has the most complete structural support content possible, providing a foundational information for the accurate generation of the knowledge graph.

[0087] It should be noted that in the diabetes knowledge graph generation task, the first step involves using entity recognition and relation extraction techniques to extract entities such as "diabetes," "insulin resistance," and "thirst and polyuria," as well as relation types such as "cause" and "manifest as" from the initially retrieved text set. These are then compared with the preset entity categories (such as disease, cause, symptom, treatment method, and complication) and relation categories (such as cause, manifestation, treatment method, and possible complications) in the task structure template. The coverage ratio of entities and relations is calculated, and the structure coverage index is determined. If the structure coverage of the current candidate text set (e.g., only 0.55) is lower than the set threshold (e.g., 0.8), the missing entity categories (e.g., treatment method and complication) and relation categories (e.g., treatment method and possible complications) are identified. Based on this, a natural language-based supplementary query is dynamically constructed (e.g., "What are the treatment methods for diabetes?" "What are the complications of diabetes?"). Dense semantic retrieval is then performed again to obtain supplementary text, thereby optimizing and improving the text set and providing more complete information support for the subsequent high-quality generation of the structure graph.

[0088] In one embodiment, S4: The text set is fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than a set threshold, knowledge graph generation is performed based on the fusion context vector, and a structured triple set containing entities, relations and attributes is output.

[0089] The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized by removing units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

[0090] The formula for calculating the coefficient of conformity for fusion quality is: In the formula, To incorporate the quality non-compliance coefficient, These are the attention weight dispersion coefficient and semantic consistency deviation coefficient after normalization, respectively.

[0091] In one embodiment, the steps for calculating the attention weight dispersion coefficient are as follows:

[0092] Let the text set be After fusion using an attention mechanism (such as Transformer), the attention weight distribution for each text is obtained. ,in, , ;

[0093] Calculate the entropy of the attention distribution , , Minimal positive numbers, avoid ;

[0094] Entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient.

[0095] It's important to note that the attention weight dispersion coefficient measures whether the distribution of attention weights is too even or lacks focus when the model fuses multiple text segments. Essentially, it calculates the entropy of the attention distribution, reflecting whether the model can concentrate attention on a few key pieces of information or apply "equal effort" to all text segments. A larger dispersion coefficient indicates a more even distribution of attention, making it difficult for the model to distinguish the importance of information. The fusion result will tend to have a "diluted" semantic expression, leading to a vague and unrepresentative fusion context.

[0096] For example, suppose we are merging 5 pieces of text, namely... - Its contents are as follows:

[0097] It describes in detail the main symptoms and mechanisms of Alzheimer's disease;

[0098] It tells a patient's story that is unrelated to treatment;

[0099] The effects of a drug on cognitive decline were mentioned;

[0100] Include only the disease name;

[0101] It mentioned an unrelated study.

[0102] If the model's attention distribution is A = {0.45, 0.05, 0.4, 0.05, 0.05}, then the model mainly focuses on... and This is reasonable because these contexts contain key information. In this case, the attention entropy is low and the attention weight dispersion coefficient is small, indicating that the model fusion is "biased," meaning the fused context has higher information density. However, if the attention distribution is: A={0.2,0.2,0.2,0.2,0.2}; that is, the model assigns completely equal attention to each text segment, this "egalitarian" distribution often occurs when the model cannot effectively identify key points. This results in the fused context being equal to the "average" of all text content, thus masking key information. Consequently, the final generated structured triples may omit important entities or incorrectly associate unimportant content.

[0103] Therefore, the larger the attention weight dispersion coefficient, the less the model can focus on the core content, resulting in poorer fusion quality and reduced accuracy and reliability of knowledge graph generation. An excellent fusion process should have a low attention dispersion coefficient, meaning high attention concentration and a clear focus on task-related text segments.

[0104] In one embodiment, the steps for calculating the semantic consistency deviation coefficient are as follows:

[0105] Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model (such as BERT). These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ;

[0106] Then, the similarity between each fragment vector and the fused vector is calculated. : , ;

[0107] Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.

[0108] It should be noted that the semantic consistency deviation coefficient is used to measure the degree of consistency in semantic direction between the fused overall context vector and the original text segments. In text fusion tasks, an ideal fused context vector should be able to fully represent the core semantics of each text segment. If the semantic similarity between each segment and the fused context is similar, it indicates that the fused context has good representativeness; conversely, if the semantics of some segments deviate significantly from the fused vector, it indicates that there is semantic bias or conflict in the fusion process, and the overall fusion quality is poor. For example, suppose there are three text segments: Text A: "Alzheimer's disease is a progressive neurodegenerative disease." Text B: "Commonly used treatment drugs include donepezil and memantine." Text C: "Alzheimer's disease may be caused by the combined effects of genetic and environmental factors." If the fused context vector is more biased towards Text B (e.g., mentioning specific drugs), the semantic similarity with Texts A and C will decrease significantly. In this case, the standard deviation of the similarity distribution will increase, and the semantic consistency deviation coefficient will rise, indicating that the semantic expression after fusion may lack comprehensiveness and cannot accurately cover the meaning of all the original texts. Such fusion results in poor quality, and the generated knowledge graph is prone to distortion or omission of key information.

[0109] Therefore, the larger the semantic consistency deviation coefficient, the weaker the unity and representativeness of the original multi-text semantics in the fusion context, and the less reliable the fusion quality.

[0110] In one implementation, calculating the attention weight dispersion coefficient and the semantic consistency deviation coefficient is beneficial for evaluating the quality of fused context vectors in knowledge graph generation, outputting a structured set of triples containing entities, relations, and attributes. These coefficients, from the key perspectives of "reasonable attention distribution" and "reliable semantic consistency," quantitatively assess the stability and representativeness of the fused context vectors, helping to identify potential information shifts, noise interference, or semantic distortions in text fusion. Specifically, the attention weight dispersion coefficient reveals whether the model effectively focuses attention on key text segments, avoiding the introduction of redundant information due to overly even attention. The semantic consistency deviation coefficient assesses whether the fused context vectors accurately reflect the semantic core of each original text, preventing semantic deviation from the task objective. When these two indicators are within a reasonable range, the generated triples are more likely to accurately cover entities, relations, and attributes in the target domain, improving the structural integrity and semantic accuracy of the knowledge graph, and further enhancing the effectiveness and interpretability of downstream tasks such as reasoning, question answering, and retrieval. Therefore, using these two coefficients as core reference indicators for fusion quality helps to build a more robust and high-quality knowledge graph construction process.

[0111] In one embodiment, the text set is fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than a set threshold, knowledge graph generation is performed based on the fusion context vector, and a structured triple set containing entities, relations and attributes is output.

[0112] If the failure rate of the fusion quality is not less than the threshold, the text set will be fused again until the knowledge graph is generated.

[0113] It should be noted that when the fusion quality failure coefficient is less than a set threshold, it indicates that the attention weight distribution during the fusion process is reasonable, the semantic consistency is good, and the content redundancy is low. In this case, the fused context vector can be considered to have sufficient information representativeness and semantic stability, making it suitable as the input basis for downstream knowledge graph generation. The knowledge graph generation process typically uses this fused context vector, employing pre-trained language models (such as BERT, T5, ChatGPT, etc.) or structured extraction models to perform tasks such as Entity Recognition (NER), Relation Extraction (RE), and Attribute Extraction (AE), thereby extracting structured triples in the form of "entity-relation-entity" or "entity-attribute-attribute value." The specific process may include: decoding natural language fragments from the fused context vector, locating key entities using sequence labeling or question-answering extraction methods, and then combining syntactic dependency parsing, contextual attention inference of relations and attributes to ultimately form a set of triples that can be used to construct a knowledge graph.

[0114] For example, the fused context vector represents multiple research abstract fragments about "Alzheimer's disease treatment drug research." After entity recognition and relation extraction, the system identifies entities such as "Alzheimer's disease (disease)" and "donepezil (drug)," and identifies the relation "treatment." The final output triple is: (Alzheimer's disease, treatment, donepezil). It may also identify attribute information such as: "donepezil," "indication," and "mild to moderate Alzheimer's disease," forming an attribute triple: (donepezil, indication, mild to moderate Alzheimer's disease).

[0115] After standardization, deduplication, and graph structure organization, these triples can serve as nodes and edges in a knowledge graph, enabling the graph-based representation of structured knowledge for subsequent intelligent tasks such as querying, question answering, and recommendation. Therefore, once the quality of the fused contextual vectors meets the standards, they become the key semantic foundation supporting the efficient and accurate generation of knowledge graphs.

[0116] Based on the same inventive concept, embodiments of the present invention also provide a knowledge graph generation system based on RAG deduction. See also Figure 2 , Figure 2 This is a framework diagram of a knowledge graph generation system based on RAG inference provided in an embodiment of the present invention. The system includes:

[0117] The retrieval module extracts the expected entity categories, relationship categories, and domain context from the input knowledge graph generation task, and generates a task structure template as a target guide for subsequent retrieval and generation.

[0118] Preliminary text module: Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set;

[0119] Optimize the text module: Perform entity and relation coverage analysis on the candidate text set, identify the missing coverage areas, dynamically construct supplementary search queries based on the missing information, and execute supplementary searches to optimize and improve the text set;

[0120] Evaluation module: It fuses the text set and obtains the state information during the fusion process to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, it performs knowledge graph generation based on the fusion context vector and outputs a structured triple set containing entities, relations and attributes.

[0121] Knowledge graph generation module: If the fusion quality failure coefficient is not less than the threshold, the text set will be fused again until the knowledge graph is generated.

[0122] Based on the RAG-based knowledge graph generation system provided in this invention, the fusion process of the fusion mechanism can be detected through the above-described method, enabling the generation of a knowledge graph based on the fusion result. Problems in the fusion context can be identified and corrected in a timely manner, and the possibility of entity errors, relation mismatches, or attribute omissions in the generated triples is relatively small, ensuring the accuracy and usability of the knowledge graph.

[0123] The initial text module includes:

[0124] Vector encoding module: Converts expected entity categories, relation categories, and domain context information into text descriptions; uses a pre-trained language model to encode the text descriptions into dense vectors. Based on the input keywords for the specific task, a dense keyword vector is generated. ;

[0125] Fusion Vector Module: For and Perform weighted fusion to obtain the final fusion vector. ;

[0126] Cosine similarity calculation module: pre-encodes all text fragments in the candidate text library into a vector set. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ;

[0127] Candidate text set module: This module uses cosine similarity. Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

[0128] In one embodiment, the text optimization module includes:

[0129] Extraction module: Utilizing entity recognition and relation extraction technologies, it extracts the entity types and relation types contained in each candidate text from the candidate text set, and compares the entity sets and relation sets extracted from all texts with the expected entity categories and relation categories set in the task structure template.

[0130] Coverage module: Calculates the ratio between all categories in the entity set and the expected entity category, calculates the ratio between all categories in the relationship set and the expected relationship category, and adds the two ratios to obtain the structure coverage index;

[0131] Text Collection Module: When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text collection; after identifying the missing entity categories or relationship categories, a supplementary search query is constructed based on the missing information to optimize and improve the text collection.

[0132] In one embodiment, the evaluation module includes a fusion quality non-compliance coefficient calculation module, which includes:

[0133] The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized by removing units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

[0134] In one embodiment, the evaluation module further includes:

[0135] Weight distribution module: Let the text set be... After fusion using the attention mechanism, the attention weight distribution for each text is obtained. ,in, , ;

[0136] Entropy calculation module: Calculates the entropy of the attention distribution. , , Minimal positive numbers, avoid ;

[0137] Attention weight distribution module: This module distributes the entropy of attention weights. Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient;

[0138] Vector setting gate module: Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model. These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ;

[0139] Similarity calculation module: calculates the vector for each fragment. With overall context vector similarity between , ;

[0140] Semantic consistency deviation module: calculates all similarities The standard deviation was used as the semantic consistency deviation coefficient.

[0141] The foregoing has provided a detailed description of one embodiment of the present invention, but this description is merely a preferred embodiment and should not be construed as limiting the scope of the invention. All equivalent variations and modifications made within the scope of the claims of this invention should still fall within the patent coverage of this invention.

Claims

1. A knowledge graph generation method based on RAG inference, characterized in that, Includes the following steps: For the input knowledge graph generation task, the expected entity categories, relation categories and domain context are extracted from the task to generate a task structure template, which serves as a target guide for subsequent retrieval and generation. Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set; Entity and relation coverage analysis is performed on the candidate text set to identify the missing coverage areas, and supplementary search queries are dynamically constructed based on the missing information to optimize and improve the text set. The text set is fused, and the state information during the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, knowledge graph generation is performed based on the fusion context vector, and the output is a structured triple set containing entities, relations and attributes. If the failure rate of the fusion quality is not less than the threshold, the text set will be fused again until the knowledge graph is generated. The steps to perform supplementary searches to optimize and improve the text collection are as follows: Using entity recognition and relation extraction techniques, the entity type and relation type contained in each candidate text in the candidate text set are extracted, and the entity set and relation set extracted from all texts are compared with the expected entity category and relation category set in the task structure template. Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relation set and the expected relation category, and add the two ratios to obtain the structure coverage index; When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text set. After identifying the missing entity categories or relationship categories, a supplementary retrieval query is constructed based on the missing information to optimize and improve the text set.

2. The knowledge graph generation method based on RAG inference according to claim 1, characterized in that, Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set, including the following steps: The expected entity category, relation category, and domain context information are converted into text descriptions; a pre-trained language model is used to encode the text descriptions into dense vectors. Based on the input keywords for the specific task, a dense keyword vector is generated. ; right and Perform weighted fusion to obtain the final fusion vector. ; All text fragments in the candidate text library are pre-encoded into a set of vectors. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ; Cosine similarity Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

3. The knowledge graph generation method based on RAG deduction according to claim 1, characterized in that, The steps for fusing text sets, obtaining state information during the fusion process, and calculating the fusion quality failure coefficient are as follows: The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized to remove units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.

5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

4. The knowledge graph generation method based on RAG deduction according to claim 3, characterized in that, The calculation steps for the attention weight dispersion coefficient and semantic consistency deviation coefficient are as follows: Let the text set be After fusion using the attention mechanism, the attention weight distribution for each text is obtained. ,in, , ; Calculate the entropy of the attention distribution , , Minimal positive numbers, avoid ; Entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient; Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model. These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ; Calculate the vector of each fragment With overall context vector similarity between , ; Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.

5. A knowledge graph generation system based on RAG deduction, characterized in that, The system includes: The retrieval module extracts the expected entity categories, relationship categories, and domain context from the input knowledge graph generation task, and generates a task structure template as a target guide for subsequent retrieval and generation. Preliminary text module: Based on the task structure template and task keywords, a dense retrieval method is used to initially retrieve the candidate text set; Optimize text module: Perform entity and relation coverage analysis on the candidate text set, identify the missing coverage areas, dynamically construct supplementary search queries based on the missing information, and execute supplementary searches to optimize and improve the text set; Evaluation module: It fuses the text set and obtains the state information during the fusion process to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, it performs knowledge graph generation based on the fusion context vector and outputs a structured triple set containing entities, relations and attributes. Knowledge graph generation module: If the fusion quality failure coefficient is not less than the threshold, the text set will be fused again until the knowledge graph is generated. The optimized text module includes: Extraction module: Utilizing entity recognition and relation extraction technologies, it extracts the entity types and relation types contained in each candidate text from the candidate text set, and compares the entity sets and relation sets extracted from all texts with the expected entity categories and relation categories set in the task structure template. Coverage module: Calculates the ratio between all categories in the entity set and the expected entity category, calculates the ratio between all categories in the relationship set and the expected relationship category, and adds the two ratios to obtain the structure coverage index; Text Collection Module: When the structural coverage does not reach the pre-set structural coverage threshold, it indicates that there is still a lack of structural information in the current candidate text collection; after identifying the missing entity categories or relationship categories, a supplementary search query is constructed based on the missing information to optimize and improve the text collection.

6. The knowledge graph generation system based on RAG deduction according to claim 5, characterized in that, The preliminary text module includes: Vector encoding module: Converts expected entity categories, relation categories, and domain context information into text descriptions; uses a pre-trained language model to encode the text descriptions into dense vectors. Based on the input keywords for the specific task, a dense keyword vector is generated. ; Fusion Vector Module: For and Perform weighted fusion to obtain the final fusion vector. ; Cosine similarity calculation module: pre-encodes all text fragments in the candidate text library into a vector set. Calculate the final fusion vector Each vector in the set of vectors cosine similarity ; Candidate text set module: This module uses cosine similarity. Texts with a similarity threshold of at least 100% are selected as candidate texts, and a candidate text set is generated.

7. The knowledge graph generation system based on RAG deduction according to claim 5, characterized in that, The evaluation module includes a fusion quality non-compliance coefficient calculation module, which includes: The fusion quality failure coefficient includes the attention weight dispersion coefficient and the semantic consistency deviation coefficient. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are normalized to remove units and dimensions. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are each assigned a weight of 0.

5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are multiplied by their corresponding weights, and the results of the multiplication are added together to obtain the fusion quality failure coefficient.

8. The knowledge graph generation system based on RAG deduction according to claim 7, characterized in that, The evaluation module also includes: Weight distribution module: Let the text set be... After fusion using the attention mechanism, the attention weight distribution for each text is obtained. ,in, , ; Entropy calculation module: Calculates the entropy of the attention distribution. , , Minimal positive numbers, avoid ; Attention weight distribution module: This module distributes the entropy of attention weights. Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient; Vector setting gate module: Let the text set be Each text segment is encoded into a semantic vector using a pre-trained model. These text fragments are then fused into a single overall context vector using attention mechanisms and other methods. ; Similarity calculation module: calculates the vector for each fragment. With overall context vector similarity between , ; Semantic consistency deviation module: calculates all similarities The standard deviation is used as the semantic consistency deviation coefficient.

Citation Information

Patent Citations

  • Intelligent question-answering method based on micro hotel platform

    CN111831880A

  • Intelligent question and answer method, system and device for medical record writing knowledge and storage medium

    CN118447986A