Knowledge graph generation method and system based on RAG deduction
By generating task structure templates, dense retrieval and coverage analysis in the RAG method, and dynamically supplementing the retrieval to optimize the text collection, the problems of problem identification and correction in the fusion context are solved, and the accuracy and usability of knowledge graph generation are improved.
Patent Information
- Application Number
- CN202510788685.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-13
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-06-13
AI Technical Summary
Existing RAG methods fail to identify and correct problems in the fusion context in a timely manner during knowledge graph generation, resulting in entity errors, relationship mismatches, or attribute omissions in the generated triples, especially in the context of complex, multi-source heterogeneous texts, which lack accuracy and usability.
By extracting the expected entity categories, relationship categories and domain context in the task, a task structure template is generated. A dense retrieval method is used to preliminarily retrieve the candidate text set, perform entity and relationship coverage analysis, identify coverage missing areas, 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.
Effectively identify and correct problems in the fusion process, reduce entity errors, relationship mismatches or attribute omissions in the generated triples, and ensure the accuracy and usability of the knowledge graph.
Smart Images

Figure CN120633809A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of knowledge graph generation, and in particular to a method and system for generating a knowledge graph based on RAG deduction. Background Art
[0002] With the advancement of natural language processing and knowledge graph technologies, methods based on retrieval-augmented generation (RAG) have gradually become a mainstream technique for automatically constructing knowledge graphs. By combining external knowledge base retrieval with language generation models, RAG methods can generate richer and more accurate knowledge triples. Specifically, RAG methods typically follow a "retrieval-fusion-generation" process for knowledge graph generation: first, based on the user's input question or task, relevant content fragments are retrieved from a large text corpus or knowledge documents. These retrieval results are then encoded together with the original input, and contextual knowledge is introduced through fusion mechanisms such as cross-attention or splicing. Finally, a language generation model is used to understand and organize the fused information, outputting structured triples containing entities, relationships, and attributes to generate a knowledge graph. This process combines knowledge recall with language comprehension capabilities, improving both knowledge coverage and the accuracy and diversity of generated content, thus providing effective support for knowledge graph construction in complex scenarios.
[0003] However, existing RAG methods generally assume that there will be no problems in the fusion process of the fusion mechanism. Generating a knowledge graph directly based on the fusion results may result in problems in the fusion context that cannot be identified and corrected in a timely manner, which in turn leads to entity errors, relationship mismatches, or attribute omissions in the generated triples, seriously affecting the accuracy and usability of the knowledge graph. This problem is particularly prominent in complex, multi-source and heterogeneous text contexts. Summary of the Invention
[0004] The purpose of the present invention is to solve the above-mentioned problems and provide a knowledge graph generation method and system based on RAG deduction.
[0005] In the first aspect of the present invention, a knowledge graph generation method based on RAG deduction is first proposed, and the method includes: For the input knowledge graph generation task, the expected entity categories, relationship categories and domain context in the task are extracted, and the task structure template is generated as the target guide for subsequent retrieval and generation; Based on the task structure template and task keywords, using a dense search method, preliminarily searching a candidate text set; Performing entity and relationship coverage analysis on the candidate text set, identifying coverage missing areas, dynamically constructing supplementary search queries based on the missing information, and executing supplementary searches to optimize and improve the text set; The text collection is fused, and the status information of the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, the knowledge graph is generated based on the fusion context vector, and a structured triple set containing entities, relationships and attributes is output; If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum is generated.
[0006] Optionally, based on the task structure template and task keywords, a dense search method is used to preliminarily search for a candidate text set, including the following steps: Convert expected entity categories, relationship categories, and domain context information into text descriptions; use a pre-trained language model to encode text descriptions into dense vectors , input keywords based on specific tasks and generate keyword dense vectors ; right and Perform weighted fusion to obtain the final fusion vector ; Pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; The cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
[0007] Optionally, the steps of performing a supplementary search to optimize and refine the text collection are: Utilize entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compare the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories 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 relationship set and the expected relationship category, and add the two ratios to get the structural coverage index; When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing structural information in the current candidate text set; 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 set.
[0008] Optionally, the steps of fusing the text set and obtaining status information during the fusion process to calculate the fusion quality failure coefficient are: 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
[0009] Optionally, the calculation steps of the attention weight dispersion coefficient and the semantic consistency deviation coefficient are: Let the text collection be : After the attention mechanism is integrated, the attention weight distribution of each text is obtained ,in, , ; Calculating the entropy of attention distribution , , Very small positive number, avoid ; The entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to get the attention weight dispersion coefficient; Let the text collection be , use the pre-trained model to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Calculate each fragment vector and the overall context vector The similarity between , ; Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.
[0010] In a second aspect of the present invention, a knowledge graph generation system based on RAG deduction is proposed, the system comprising: Retrieval module: Generates tasks based on the input knowledge graph, extracts expected entity categories, relationship categories, and domain context in the 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 search method is used to preliminarily search for a candidate text set; Optimize text module: perform entity and relationship coverage analysis on the candidate text set, identify coverage missing areas, dynamically construct supplementary search queries based on the missing information, and perform supplementary searches to optimize and improve the text set; Evaluation module: Fusion of text collections, acquisition of fusion status information, and calculation of 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, relationships, and attributes is output. Knowledge spectrum generation module: If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum generation is completed.
[0011] Optionally, the preliminary text module includes: Vector encoding module: converts expected entity categories, relationship categories and domain context information into text descriptions; uses pre-trained language models to encode text descriptions into dense vectors , input keywords based on specific tasks and generate keyword dense vectors ; Fusion vector module: and Perform weighted fusion to obtain the final fusion vector ; Cosine similarity calculation module: pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; Candidate text collection module: Cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
[0012] Optionally, the text optimization module includes: Extraction module: Utilizes entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compares the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories set in the task structure template; Coverage module: Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relationship set and the expected relationship category, and add the two ratios to obtain the structural coverage index; Text collection module: When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing 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.
[0013] Optionally, the evaluation module includes a fusion quality unqualified coefficient calculation module, and the fusion quality unqualified coefficient calculation module 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
[0014] Optionally, the evaluation module further includes: Weight distribution module: Let the text collection be : After the attention mechanism is integrated, the attention weight distribution of each text is obtained ,in, , ; Entropy calculation module: calculate the entropy of attention distribution , , Very small positive number, avoid ; Attention weight distribution module: the entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to get the attention weight dispersion coefficient; Vector setting gate module: Set the text set to , use the pre-trained model to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Similarity calculation module: calculate the vector of each fragment and the overall context vector The similarity between , ; Semantic consistency deviation module: calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.
[0015] Beneficial effects of the present invention: The present invention proposes a knowledge graph generation method and system based on RAG deduction. By generating a task for the input knowledge graph, the expected entity categories, relationship categories and domain context in the task are extracted, and a task structure template is generated 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 preliminarily retrieve the candidate text set; the entity and relationship coverage of the candidate text set is analyzed to identify the coverage missing areas, and a supplementary retrieval query is dynamically constructed based on the missing information, and a supplementary retrieval is performed to optimize and improve the text set; the text set is fused, and the state information of the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, the knowledge graph is generated based on the fusion context vector, and a structured triple set containing entities, relationships and attributes is output; if the fusion quality failure coefficient is not less than the threshold, the text set is fused again until the knowledge spectrum graph is generated. In this way, the fusion process of the fusion mechanism can be detected, so that a knowledge spectrum graph is generated according to the fusion result. Problems in the fusion 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, ensuring the accuracy and availability of the knowledge graph. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The present invention will be further described below with reference to the accompanying drawings.
[0017] Figure 1 Flowchart of the knowledge graph generation method based on RAG deduction; Figure 2 Framework diagram of the knowledge graph generation system based on RAG deduction. DETAILED DESCRIPTION
[0018] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0019] The embodiment of the present invention provides a knowledge graph generation method based on RAG deduction. Figure 1 , Figure 1 Flowchart of a method for generating a knowledge graph based on RAG deduction provided in an embodiment of the present invention. The method comprises the following steps: For the input knowledge graph generation task, the expected entity categories, relationship categories and domain context in the task are extracted, and the task structure template is generated as the target guide for subsequent retrieval and generation; Based on the task structure template and task keywords, a dense search method is used to preliminarily search for a set of candidate texts; Perform entity and relationship coverage analysis on the candidate text collection, identify coverage gaps, dynamically construct supplementary search queries based on the missing information, and perform supplementary searches to optimize and improve the text collection; The text collection is fused, and the status information of the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, the knowledge graph is generated based on the fusion context vector, and a structured triple set containing entities, relationships and attributes is output; If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum is generated.
[0020] The RAG-based knowledge graph generation method provided by the embodiments of the present invention, through the above-mentioned method, can detect the fusion process of the fusion mechanism, so that a knowledge graph can be generated based on the fusion results. Problems in the fusion context can be promptly identified and corrected, and the generated triples are less likely to contain entity errors, relationship mismatches, or attribute omissions, thus ensuring the accuracy and usability of the knowledge graph.
[0021] In one embodiment, a task is generated based on the input knowledge graph, and the expected entity categories, relationship categories, and domain context in the task are extracted to generate a task structure template as a target guide for subsequent retrieval and generation; It should be noted that the core goal of extracting the expected entity categories, relationship categories, and domain context from the input knowledge graph generation task and generating the task structure template is to transform the task intent described in natural language into a structured "expected graph framework" to guide subsequent retrieval and generation. This process generally includes four key steps: task semantic parsing, domain context identification, structural element extraction, and structural template construction.
[0022] First, the task input is received from the user or upper layer. This input may be a natural language question, description, text, or query instruction. The task text is analyzed through a semantic parsing module (such as a Transformer-based semantic role tagger or named entity recognizer) to identify key entity fragments related to the knowledge graph (such as proper nouns, organizations, people, and places) and candidate relational verbs or phrases (such as "belong to," "serve as," "be located in," and "involve"). Simultaneously, the input text is contextually modeled using a pre-trained language model and domain dictionary to identify the domain to which the task belongs (such as law, healthcare, finance, etc.) and determine the domain knowledge boundaries and background preferences involved in the task.
[0023] Next, based on the identified entities and relationships, and in conjunction with knowledge graph construction specifications (such as whether it is triple-oriented and whether it requires attribute information), a preliminary structural target framework is constructed. This framework is not a complete knowledge graph, but rather a rough sketch of the desired structure for the task, containing several expected triple placeholder structures. Each structure may be represented as (entity 1 type, placeholder relationship, entity 2 type), and uncertainty areas may be annotated.
[0024] Suppose the input knowledge graph generation task is: "Please construct a knowledge graph about 'Alzheimer's disease treatment plan'." First, perform semantic parsing on this input. Through the named entity recognition model, "Alzheimer's disease" is identified as the core medical disease entity, and it is detected that "treatment plan" implies the existence of multiple related medical entity categories, such as "drug name", "treatment method", "research institution", "side effect", etc. Then, the relationship extraction model is used to perform semantic matching with the medical knowledge ontology library to identify potential important relationship types in this task, including "treated (drug_treats)", "researched by (researched_by)", "side effect is (has_side_effect)", etc. At the same time, by analyzing the similarity between the task keywords and the knowledge base field labels, it is judged that the task field belongs to the "neuromedicine / disease treatment" category, and the specific terminology and structural preferences of this field are loaded. After integrating the above information, the following task structure template is constructed: Entity categories: disease (Alzheimer's disease), drug, treatment, research institution, side effects; Relationship type: treated, studied in, side effects are, indications are; Domain Context: Neurodegenerative diseases, geriatric medicine, clinical treatment.
[0025] In one implementation method, each task structure template not only clearly defines the types of entities and relationships that should be covered by subsequent retrieval and generation, but also provides semantic constraints in the context field for the generation stage, so that the final generated knowledge graph is more in line with the task intent and has more logical structure and application value.
[0026] In one embodiment, S2: Based on the task structure template and the task keywords, a dense search method is used to preliminarily search the candidate text set, including the following steps: Convert expected entity categories, relationship categories, and domain context information into text descriptions; for example, "contains disease entities, drug entities, and 'treatment' relationships"; Use pre-trained language models (such as BERT, SimCSE, etc.) to encode text descriptions into dense vectors , input keywords (such as "Alzheimer's disease", "drug", "treatment") based on specific tasks to generate keyword dense vectors ; right and Perform weighted fusion to obtain the final fusion vector ; Pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; The cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
[0027] It should be noted that, taking the knowledge graph generation task of "Alzheimer's disease drug treatment" as an example, the expected structural objectives are first extracted from the task, such as the need to include "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 a structural description text: "The text should include the name of Alzheimer's disease-related drugs, treatment relationships, and their mechanisms of action." Furthermore, the user task input includes the 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 to obtain two dense semantic vectors. These are then fused into a unified fused 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 segment vectors are retrieved from a large medical text library, and cosine similarity is calculated with the fused vector. Passages with a similarity of at least 0.75 are selected as candidate texts. For example, the text segment "Donepezil is a drug commonly used to treat Alzheimer's disease that improves cognitive function by inhibiting acetylcholinesterase" was identified as a highly matched text and included in the candidate set because it contains both disease entities, drug entities, and a therapeutic relationship. However, paragraphs unrelated to the task structure, such as "Diabetic patients should pay attention to dietary control," were excluded. This process initially constructed a text set with high structural relevance, laying the foundation for subsequent structural coverage analysis and graph generation.
[0028] In one embodiment, S3: performing entity and relationship coverage analysis on the candidate text set, identifying coverage missing areas, and dynamically constructing a supplementary search query based on the missing information. The steps of performing the supplementary search to optimize and improve the text set are: Utilize entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compare the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories 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 relationship set and the expected relationship category, and add the two ratios to get the structural coverage index; When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing structural information in the current candidate text set; 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 set.
[0029] This query converts missing structural elements into textual supplementary descriptions, combines them with task context keywords to construct a semantically complete extended query description, and then uses a semantic encoding model to convert it into a dense vector representation. A targeted dense search is then performed to obtain text fragments that are highly relevant to the missing structure. Subsequently, the text fragments obtained from the supplementary search are incorporated into the original candidate set, forming a text set with higher structural coverage. This ensures that the subsequent fusion generation process has the most complete structural support possible, providing the information foundation for the accurate generation of the knowledge graph.
[0030] It should be noted that in the diabetes knowledge graph generation task, first, from the initially retrieved text collection, entity recognition and relationship extraction technology are used to extract entities such as "diabetes", "insulin resistance", "thirst and polyuria" and relationship types such as "cause" and "manifested as", and compare them with the preset entity categories (such as disease, cause, symptoms, treatment methods, complications) and relationship categories (such as cause, manifestation, treatment methods, possible complications) in the task structure template, and count the coverage ratios of their entities and relationships, and calculate the structural coverage index; if the structural coverage of the current candidate text collection (such as only 0.55) is lower than the set threshold (such as 0.8), the missing entity categories (such as treatment methods, complications) and relationship categories (such as treatment methods, possible complications) are identified, and based on this, a supplementary query in natural language form (such as "What are the treatments for diabetes?" "What are the complications of diabetes?") is dynamically constructed, and dense semantic retrieval is re-executed to obtain supplementary text, thereby optimizing and improving the text collection, and providing more complete information support for the subsequent high-quality generation of structural graphs.
[0031] In one embodiment, S4: fusing the text collection, obtaining status information during the fusion process, and calculating a fusion quality failure coefficient. When the fusion quality failure coefficient is less than a set threshold, generating a knowledge graph based on the fusion context vector and outputting a structured triple set containing entities, relationships, and attributes. 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
[0032] The calculation formula for the fusion quality unqualified coefficient is: , where is the fusion quality failure coefficient, They are the normalized attention weight dispersion coefficient and semantic consistency deviation coefficient respectively.
[0033] In one embodiment, the steps for calculating the attention weight distribution coefficient are: Let the text collection be : After the attention mechanism (such as Transformer) is integrated, the attention weight distribution of each text is obtained ,in, , ; Calculating the entropy of attention distribution , , Very small positive number, avoid ; The entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to obtain the attention weight dispersion coefficient.
[0034] It's important to note that the attention weight dispersion coefficient measures whether the model's attention weight distribution is too evenly distributed and lacks focus when fusing multiple text segments. Essentially, it calculates the entropy of the attention distribution, reflecting whether the model is able to focus on a few key pieces of information or apply evenly across all text segments. A larger dispersion coefficient indicates a more evenly distributed attention, making it more difficult for the model to distinguish the importance of information. The resulting fusion results tend to be "diluted," resulting in a vague and unrepresentative fusion context.
[0035] For example, suppose we are merging five texts, namely - Its contents are as follows: Describes in detail the main symptoms and mechanisms of "Alzheimer's disease"; Telling a patient story that has nothing to do with treatment; Mention the effect of a drug on cognitive decline; Include only the name of the disease; : An unrelated study was mentioned.
[0036] If the model attention distribution is: A={0.45,0.05,0.4,0.05,0.05}, it means that the model mainly focuses on and This is reasonable because they 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," that is, the fusion context has higher information density. However, if the attention distribution is: A = {0.2, 0.2, 0.2, 0.2}; that is, the model gives exactly the same attention to each paragraph of text, this "egalitarian" distribution often occurs when the model cannot effectively identify key points, resulting in the fusion context being equal to the "average" of all text content, thus obscuring key information. The resulting structured triples may omit important entities or incorrectly associate unimportant content.
[0037] Therefore, a larger attention weight dispersion coefficient indicates that the model is less able to 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 concentration and clear focus on task-related text segments.
[0038] In one embodiment, the steps for calculating the semantic consistency deviation coefficient are: Let the text collection be , use a pre-trained model (such as BERT) to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Then calculate the similarity between each segment vector and the fusion vector : , ; Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.
[0039] It should be noted that the semantic consistency deviation coefficient measures the degree of semantic consistency between the fused overall context vector and the original text segments. In text fusion tasks, an ideal fused context vector should fully represent the core semantics of each text segment. If each segment has a similar semantic similarity to the fused context, the fused context is well representative. Conversely, if the semantics of some segments deviate significantly from the fused vector, it indicates semantic deviation or conflict during the fusion process, resulting in poor overall fusion quality. For example, consider three text segments: Text A: "Alzheimer's disease is a progressive neurodegenerative disease." Text B: "Currently commonly used therapeutic drugs include donepezil and memantine." Text C: "Alzheimer's disease may be caused by a combination of genetic and environmental factors." If the fused context vector is more biased towards Text B (e.g., it mentions specific drugs), the semantic similarity with Texts A and C will significantly decrease. In this case, the standard deviation of the similarity distribution will increase, and the semantic consistency deviation coefficient will rise, indicating that the fused semantic representation may lack comprehensiveness and fail to accurately cover the meaning of all the original texts. The quality of such fusion is poor, and the generated knowledge graph is prone to distortion or omission of key information.
[0040] Therefore, the larger the semantic consistency deviation coefficient is, the weaker the unity and representativeness of the fusion context to the original multi-text semantics is, and the less reliable the fusion quality is.
[0041] In one implementation, calculating the attention weight dispersion coefficient and semantic consistency deviation coefficient is beneficial for measuring the quality of the fused context vector in knowledge graph generation, outputting a structured set of triples containing entities, relations, and attributes. These coefficients quantitatively assess the stability and representativeness of the fused context vector from two key perspectives: the rationality of attention distribution and the reliability of semantic consistency. This helps to proactively identify potential issues such as information drift, noise interference, or semantic distortion 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 balanced attention. The semantic consistency deviation coefficient, on the other hand, assesses whether the fused context vector truly reflects the semantic core of each original text, preventing semantic deviation from the task objective. When these two metrics are within a reasonable range, the generated triples are more likely to accurately cover the entities, relations, and attributes of 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 of fusion quality will help build a more robust and high-quality knowledge graph construction process.
[0042] In one embodiment, a text collection is fused, and state information of the fusion process is obtained to calculate a fusion quality failure coefficient. When the fusion quality failure coefficient is less than a set threshold, a knowledge graph is generated based on the fusion context vector, and a structured triple set containing entities, relationships, and attributes is output. If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum is generated.
[0043] It should be noted that when the fusion quality failure coefficient is less than the set threshold, it indicates that the attention weight distribution during the fusion process is reasonable, semantic consistency is good, and content redundancy is low. At this point, 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 is typically based on this fused context vector, using 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). This process then extracts structured triples in the form of "entity-relationship-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 analysis and contextual attention to infer relationships and attributes to ultimately form a set of triples that can be used to construct the knowledge graph.
[0044] For example, a fused context vector represents multiple scientific research abstracts on "Alzheimer's disease treatment drug research." After entity recognition and relationship extraction, the system identifies entities such as "Alzheimer's disease (disease)" and "Donepezil (drug)" and the relationship "treatment," ultimately outputting the triple: (Alzheimer's disease, treatment, donepezil). It can also identify attribute information such as "donepezil," "indications," and "mild to moderate Alzheimer's disease," forming the attribute triple: (donepezil, indications, mild to moderate Alzheimer's disease).
[0045] After format standardization, deduplication, and graph organization, these triples can serve as nodes and edges in the knowledge graph, enabling a graphical representation of structured knowledge for subsequent intelligent tasks such as querying, question-answering, and recommendations. Therefore, once the fused context vector meets quality standards, it becomes the key semantic foundation supporting the efficient and accurate generation of the knowledge graph.
[0046] Based on the same inventive concept, the present invention also provides a knowledge graph generation system based on RAG deduction. Figure 2 , Figure 2 A framework diagram of a knowledge graph generation system based on RAG deduction provided in an embodiment of the present invention, the system comprising: Retrieval module: Generates tasks based on the input knowledge graph, extracts expected entity categories, relationship categories, and domain context in the 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, it uses dense retrieval methods to preliminarily retrieve the candidate text set; Optimize Text Module: Analyze entity and relationship coverage of candidate text sets, identify areas with missing coverage, dynamically construct supplementary search queries based on missing information, and perform supplementary searches to optimize and improve the text set; Evaluation module: Fusion of text collections, acquisition of fusion status information, and calculation of 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, relationships, and attributes is output. Knowledge spectrum generation module: If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum generation is completed.
[0047] The RAG-based knowledge graph generation system provided by the embodiments of the present invention can detect the fusion process of the fusion mechanism through the above-mentioned method, so that a knowledge graph can be generated based on the fusion results. Problems in the fusion context can be promptly identified and corrected, and the generated triples are less likely to contain entity errors, relationship mismatches, or attribute omissions, thus ensuring the accuracy and usability of the knowledge graph.
[0048] The preliminary text modules include: Vector encoding module: converts expected entity categories, relationship categories and domain context information into text descriptions; uses pre-trained language models to encode text descriptions into dense vectors , input keywords based on specific tasks and generate keyword dense vectors ; Fusion vector module: and Perform weighted fusion to obtain the final fusion vector ; Cosine similarity calculation module: pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; Candidate text collection module: Cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
[0049] In one embodiment, the optimized text module includes: Extraction module: Utilizes entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compares the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories set in the task structure template; Coverage module: Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relationship set and the expected relationship category, and add the two ratios to obtain the structural coverage index; Text collection module: When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing 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.
[0050] In one embodiment, the evaluation module includes a fusion quality unqualified coefficient calculation module, and the fusion quality unqualified coefficient calculation module 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
[0051] In one embodiment, the evaluation module further comprises: Weight distribution module: Let the text collection be : After the attention mechanism is integrated, the attention weight distribution of each text is obtained ,in, , ; Entropy calculation module: calculate the entropy of attention distribution , , Very small positive number, avoid ; Attention weight distribution module: the entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to get the attention weight dispersion coefficient; Vector setting gate module: Set the text set to , use the pre-trained model to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Similarity calculation module: calculate the vector of each fragment and the overall context vector The similarity between , ; Semantic consistency deviation module: calculate all similarities The standard deviation of The above is a detailed description of an embodiment of the present invention, but the content is only a preferred embodiment of the present invention and should not be considered to limit the scope of the present invention. All equivalent changes and improvements made within the scope of the present invention should still fall within the scope of the patent coverage of the present invention.
Claims
1. The knowledge graph generation method based on RAG deduction is characterized by: The following steps are involved: For the input knowledge graph generation task, the expected entity categories, relationship categories and domain context in the task are extracted, and the task structure template is generated as the target guide for subsequent retrieval and generation; Based on the task structure template and task keywords, using a dense search method, preliminarily searching a candidate text set; Performing entity and relationship coverage analysis on the candidate text set, identifying coverage missing areas, dynamically constructing supplementary search queries based on the missing information, and executing supplementary searches to optimize and improve the text set; The text collection is fused, and the status information of the fusion process is obtained to calculate the fusion quality failure coefficient. When the fusion quality failure coefficient is less than the set threshold, the knowledge graph is generated based on the fusion context vector, and a structured triple set containing entities, relationships and attributes is output; If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum is generated.
2. The knowledge graph generation method based on RAG deduction according to claim 1 is characterized in that: Based on the task structure template and task keywords, a dense search method is used to preliminarily search for a candidate text set, including the following steps: Convert expected entity categories, relationship categories, and domain context information into text descriptions; use a pre-trained language model to encode text descriptions into dense vectors , input keywords based on specific tasks and generate keyword dense vectors ; right and Perform weighted fusion to obtain the final fusion vector ; Pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; The cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
3. The knowledge graph generation method based on RAG deduction according to claim 1 is characterized in that: The steps to perform a supplemental search to refine and improve your text collection are: Utilize entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compare the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories 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 relationship set and the expected relationship category, and add the two ratios to get the structural coverage index; When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing structural information in the current candidate text set; 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 set.
4. The knowledge graph generation method based on RAG deduction according to claim 1 is characterized in that: The steps of fusing the text set and obtaining the status information of the fusion process to calculate 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.
5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
5. The knowledge graph generation method based on RAG deduction according to claim 4 is characterized in that: The calculation steps of the attention weight dispersion coefficient and the semantic consistency deviation coefficient are as follows: Let the text collection be : After the attention mechanism is integrated, the attention weight distribution of each text is obtained ,in, , ; Calculating the entropy of attention distribution , , Very small positive number, avoid ; The entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to get the attention weight dispersion coefficient; Let the text collection be , use the pre-trained model to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Calculate each fragment vector and the overall context vector The similarity between , ; Calculate all similarities The standard deviation is used as the semantic consistency deviation coefficient.
6. The knowledge graph generation system based on RAG deduction is characterized by: The system comprises: Retrieval module: Generates tasks based on the input knowledge graph, extracts expected entity categories, relationship categories, and domain context in the 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 search method is used to preliminarily search for a candidate text set; Optimize text module: perform entity and relationship coverage analysis on the candidate text set, identify coverage missing areas, dynamically construct supplementary search queries based on the missing information, and perform supplementary searches to optimize and improve the text set; Evaluation module: Fusion of text collections, acquisition of fusion status information, and calculation of 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, relationships, and attributes is output. Knowledge spectrum generation module: If the fusion quality failure coefficient is not less than the threshold, the text collection will be fused again until the knowledge spectrum generation is completed.
7. The knowledge graph generation system based on RAG deduction according to claim 6 is characterized in that: The preliminary text module includes: Vector encoding module: converts expected entity categories, relationship categories and domain context information into text descriptions; uses pre-trained language models to encode text descriptions into dense vectors , input keywords based on specific tasks and generate keyword dense vectors ; Fusion vector module: and Perform weighted fusion to obtain the final fusion vector ; Cosine similarity calculation module: pre-encode all text fragments in the candidate text library into a vector set , calculate the final fusion vector and each vector in the vector set Cosine similarity of ; Candidate text collection module: Cosine similarity Texts with a similarity not less than a preset threshold are selected as candidate texts to generate a candidate text set.
8. The knowledge graph generation system based on RAG deduction according to claim 6 is characterized in that: The optimized text module includes: Extraction module: Utilizes entity recognition and relationship extraction technology to extract the entity types and relationship types contained in each candidate text in the candidate text set, and compares the entity sets and relationship sets extracted from all texts with the expected entity categories and relationship categories set in the task structure template; Coverage module: Calculate the ratio between all categories in the entity set and the expected entity category, calculate the ratio between all categories in the relationship set and the expected relationship category, and add the two ratios to obtain the structural coverage index; Text collection module: When the structure coverage does not reach the pre-structure coverage threshold, it means that there is still missing 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.
9. The knowledge graph generation system based on RAG deduction according to claim 6 is characterized in that: The evaluation module includes a fusion quality unqualified coefficient calculation module, and the fusion quality unqualified coefficient calculation module 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 the unit and dimension. The normalized attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively assigned a weight of 0.
5. The attention weight dispersion coefficient and the semantic consistency deviation coefficient are respectively multiplied by the corresponding weights, and the multiplication results are added together to obtain the fusion quality failure coefficient.
10. The knowledge graph generation system based on RAG deduction according to claim 9 is characterized in that: The evaluation module further includes: Weight distribution module: Let the text collection be : After the attention mechanism is integrated, the attention weight distribution of each text is obtained ,in, , ; Entropy calculation module: calculate the entropy of attention distribution , , Very small positive number, avoid ; Attention weight distribution module: the entropy of attention distribution Divide by the entropy of the preset maximum attention distribution to get the attention weight dispersion coefficient; Vector setting gate module: Set the text set to , use the pre-trained model to encode each text segment into a semantic vector , these text fragments are integrated into an overall context vector through attention mechanisms and other methods ; Similarity calculation module: calculate the vector of each fragment and the overall context vector The similarity between , ; Semantic consistency deviation module: calculate 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
Generative question answering method and system based on knowledge graph and document retrieval integration
CN119046448A
Knowledge graph completion method based on deep semantics and entity category information extraction
CN119204178A
Enhanced document generation and retrieval method based on knowledge graph
CN119646178A
Cited By
Method and system for automatically extracting defense knowledge in unstructured text
CN121351951A