Construction method and device of instruction generation agent based on knowledge graph, medium and equipment
By constructing an instruction generation agent based on knowledge graphs, using the knowledge graph structure relationship and the agent quality evaluation strategy, the problem of uncontrollable instruction data types and low quality is solved, and efficient generation of high-quality and diversified instruction data is achieved.
Patent Information
- Application Number
- CN202510491591.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2025-08-01
AI Technical Summary
The types of instruction data generated in the prior art are uncontrollable and have a single category and low quality, which affects the diversity and quality of instruction data.
By constructing instructions based on knowledge graphs, focusing on key entities using knowledge graph structural relationships, dynamically generating different types of inference planning paths, and using agent quality evaluation strategies to rewrite instructions to ensure the diversity and quality of generated instruction data.
It realizes efficient generation of high-quality and diverse instruction data, reduces model illusions, improves the complexity and quality of instruction data, and ensures excellent performance in specific fields.
Smart Images

Figure CN120409641A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence, and particularly relates to a method, device, medium and equipment for constructing an instruction generation intelligent agent based on a knowledge graph. Background Art
[0002] In recent years, large language models (LLMs) have shown excellent performance in various natural language processing (NLP) tasks. However, facing different application scenarios and industries with their specific requirements, it is difficult for general LLMs to fully meet them. Therefore, for instruction data of different types and fields, fine-tuning the large language model on instructions can make full use of the knowledge learned from pre-training while learning new knowledge in different fields, thereby showing excellent generalization ability in handling tasks never seen before. Therefore, the quality of instruction data is crucial for the success of instruction fine-tuning.
[0003] Currently, the most common way to generate instructions is to manually construct a small number of seed instruction sets, and then use black-box models such as ChatGPT to automatically construct large-scale instruction data according to the form and tasks of the seed instructions based on the prompt words, and then use this instruction data to fine-tune the open-source large language model. This method can generate a large amount of instruction data at a low cost, thereby constructing a large language model that performs excellently in a specific field. However, the quality and complexity of the instruction data generated by this method are relatively low.
[0004] Based on the above problems, some studies have proposed to generate knowledge seeds from the knowledge graph, generate positive and negative sample entity sets according to the knowledge seeds, and generate positive and negative sample instruction data based on the entity sets respectively. Although this method improves the quality of data samples, the negative sample data generated may have an impact of hallucination on the model. In addition, the types of instruction data generated by this method are single, affecting the diversity of instruction data. Summary of the Invention
[0005] Based on the above background, the present invention aims to solve the problems in the prior art that the types of generated instructions are uncontrollable and single, and the quality of instructions is relatively low, thereby providing a method, device, medium and equipment for constructing an instruction generation intelligent agent based on a knowledge graph.
[0006] To achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a method for constructing an instruction generation intelligent agent based on a knowledge graph, including,
[0008] Obtain text, extract triples in the text and connect the triple data to a graph database, and construct a text knowledge graph based on a knowledge graph construction algorithm;
[0009] Based on the text knowledge graph, perform statistical analysis on the text knowledge graph from aspects of entities, relationships, and graph structure;
[0010] Based on the statistical analysis results of the knowledge graph, construct an instruction generation agent, including constructing an agent planning module, an agent tool module, an agent storage module, and an agent execution module; specifically:
[0011] Based on the statistical analysis results of the knowledge graph, construct an agent planning module to judge the category of the instruction pair to be generated and generate the corresponding inference planning path;
[0012] Construct an agent tool module, select the initial node and call the graph database to explore the knowledge graph, and process the returned results of the exploration to construct a triple chain containing entity, relationship, and structure information;
[0013] Construct an agent storage module, which is divided into short-term storage and long-term storage. The short-term storage is used to store triple chain information, and the long-term storage is used to store prompt word templates for various tasks, including inference planning path prompt words, instruction generation prompt words for different categories, quality classification prompt words, and / or instruction rewriting prompt words;
[0014] Construct an agent execution module. Based on the inference planning path, read the instruction generation prompt words for the corresponding category and the currently stored triple chain from the agent storage module to perform the instruction generation operation, and read the quality classification prompt words for the corresponding category from the agent storage module to evaluate and classify the quality of the instruction pair. Based on the evaluation and classification results, perform the instruction rewriting operation on the data with unqualified quality classification.
[0015] In the second aspect, the present invention provides a device for constructing an instruction generation agent based on a knowledge graph, including,
[0016] A knowledge graph construction module, which is used to obtain text, extract triples in the text and connect the triple data to a graph database, and construct a text knowledge graph based on a knowledge graph construction algorithm;
[0017] A knowledge graph statistical analysis module, which is used to perform statistical analysis on the text knowledge graph from aspects of entities, relationships, and graph structure based on the text knowledge graph;
[0018] An instruction generation agent construction module, which is used to construct an instruction generation agent based on the statistical analysis results of the knowledge graph, including constructing an agent planning unit, an agent tool unit, an agent storage unit, and an agent execution unit; specifically:
[0019] An agent planning unit, which is used to judge the category of the instruction pair to be generated based on the statistical analysis results of the knowledge graph and generate the corresponding inference planning path;
[0020] An agent tool unit for selecting an initial node and invoking a graph database for knowledge graph exploration, and processing the exploration return results to construct a triple chain containing entity, relationship, and structure information;
[0021] An agent storage unit for storing data, including short-term storage and long-term storage. The short-term storage is used to store triple chain information, and the long-term storage is used to store prompt word templates for various tasks, including inference planning path prompt words, different category instruction generation prompt words, quality classification prompt words, and / or instruction rewriting prompt words;
[0022] An agent execution unit for generating instruction generation operations based on the inference planning path, reading the corresponding category instruction generation prompt words and the currently stored triple chain from the agent storage module, and reading the corresponding category quality classification prompt words from the agent storage module to evaluate and classify the quality of the instructions, and performing instruction rewriting operations on the data with unqualified quality classification based on the evaluation classification results.
[0023] In a third aspect, the present invention provides a non-transitory computer-readable storage medium, in which a computer program is stored, and the computer program is loaded and executed by a processor to implement the construction method of the instruction generation agent based on the knowledge graph as described above.
[0024] In a fourth aspect, the present invention provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the construction method of the instruction generation agent based on the knowledge graph as described above.
[0025] The beneficial effects of the present invention are as follows:
[0026] (1) The present invention uses the structural relationship of the knowledge graph to focus on key entities to construct a triple chain as context knowledge points, thereby enhancing the complexity and quality of the instruction pairs and reducing the hallucinations generated by the model itself;
[0027] (2) And different sampling strategies are adopted to dynamically generate different types of inference planning paths, and the majority voting strategy is used to select the most suitable instruction pair category and inference planning path; that is, the agent is used to dynamically construct the optimal instruction pair category, thereby increasing the diversity of instruction data;
[0028] (3) And by designing an agent instruction quality evaluation strategy and performing instruction rewriting operations based on the quality evaluation results, while ensuring the diversity of instruction data categories, the quality of the generated instruction pairs is ensured, so as to obtain a high-quality and diverse fine-tuning instruction set in an efficient and low-cost manner. Description of the Drawings
[0029] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0030] Figure 1 It is a flowchart of a method for constructing an instruction generation intelligent agent based on a knowledge graph provided by an embodiment of the present invention;
[0031] Figure 2 It is a flowchart of a device for constructing an instruction generation intelligent agent based on a knowledge graph provided by an embodiment of the present invention. Detailed implementation manners
[0032] To further understand the present invention, the following describes the preferred implementation schemes of the present invention in combination with embodiments. However, it should be understood that these descriptions are only for further explaining the features and advantages of the present invention, rather than limiting the claims of the present invention.
[0033] Embodiment 1:
[0034] This embodiment provides a method for constructing an instruction generation intelligent agent based on a knowledge graph, including:
[0035] S1. Obtain text and extract triples in the text to construct a text knowledge graph;
[0036] S2. Based on the text knowledge graph, perform statistical analysis on the text knowledge graph from aspects of entities, relationships, and graph structures;
[0037] S3. Based on the statistical analysis results of the knowledge graph, construct an instruction generation intelligent agent, including constructing an intelligent agent planning module, an intelligent agent tool module, an intelligent agent storage module, and an intelligent agent execution module; specifically:
[0038] S301. Based on the statistical analysis results of the knowledge graph, construct an intelligent agent planning module to judge the category of the instruction to be generated and generate a corresponding inference planning path;
[0039] S302. Construct an intelligent agent tool module to select an initial node, call the Neo4j graph database for knowledge graph exploration, and process the returned results to construct a triple chain containing entity, relationship, and structure information;
[0040] S303. Construct an intelligent agent storage module, which is divided into short-term storage and long-term storage. The triple information is used for short-term storage, and various task prompt templates are used for long-term storage; the prompt template refers to different category instruction generation tasks and instruction rewriting tasks;
[0041] S304. Construct an agent execution module, which includes instruction generation and instruction rewriting operations; based on the inference planning path, read the corresponding category of prompt word templates from the agent storage module to perform the instruction generation operation, evaluate and classify the quality of the instruction pairs, and perform the instruction rewriting operation on the data with unqualified quality classification based on the evaluation classification results.
[0042] The process is as Figure 1 shown. In this embodiment, the legal and regulatory data set is taken as an example for specific illustration.
[0043] In step S1, obtain the text, extract the triples in the text, and construct a text knowledge graph, which specifically includes the following steps:
[0044] S101: Construct the schema information Schema of the knowledge graph and extract the triples in the text according to the schema information; for example, the entity types include people, locations, organizations, etc.; the schema information Schema refers to the data structure that controls the extraction target and relationship pattern.
[0045] For example, in this embodiment, the input text is: Article 1. For the purpose of strengthening work safety, preventing and reducing work safety accidents, protecting the lives and property of the people, and promoting the sustainable and healthy development of the economic society, this Law is formulated... Establish a mechanism in which production and business operation entities are responsible, employees participate, government supervision is exercised, industry self-discipline is practiced, and social supervision is carried out. Article 4. Production and business operation entities must abide by this Law and other relevant laws and regulations on work safety, strengthen work safety management... Construct a dual prevention mechanism for safety risk grading control and hidden danger investigation and treatment, improve the risk prevention and resolution mechanism, improve the work safety level, and ensure work safety.
[0046] The relevant triples extracted from the text include: (production and business operation entity, responsible for, work safety) and so on;
[0047] S102: Based on the above-constructed triple data, store it in a CSV file, use the Python library to read the CSV file and connect it to the Neo4j graph database, and create nodes and edges and connect them into a network through the knowledge graph construction algorithm, that is, adopt a pattern-aware code hinting and principle-enhanced knowledge graph construction method (such as CodeKGC) to construct the knowledge graph. Among them, the Neo4j graph database is a high-performance NoSQL graph database that stores structured data on the network.
[0048] In step S2, statistically analyze the text knowledge graph from three aspects: entities, relationships, and graph structures, which specifically includes the following steps:
[0049] S201: Based on the text knowledge graph, statistically analyze its entity types and the frequencies of entity occurrences;
[0050] In this embodiment, the statistical analysis results of entity types are as follows: organization: 8 times, event: 13 times,..., person: 3 times;
[0051] The statistical analysis results of the occurrence frequency of entities are as follows: production and operation unit: 7 times, work safety: 4 times,..., society: 1 time.
[0052] S202: Based on the text knowledge graph, conduct statistical analysis on its relationship types and the occurrence frequency of relationships;
[0053] In this embodiment, the statistical analysis results of relationship types are as follows: attribute relationship: 6 times, hierarchical relationship: 4 times, causal relationship: 2 times, set relationship: 2 times;
[0054] The statistical analysis results of the occurrence frequency of relationships are as follows: be responsible for: 1 time, prevent: 1 time, improve: 1 time,..., adhere to: 1 time.
[0055] S203: Based on the text knowledge graph, conduct statistical analysis on the topological complexity and path characteristics of the graph, where the topological complexity includes average degree, clustering coefficient, and number of connected components, and the path characteristics include average path length and longest path;
[0056] In this embodiment, the statistical analysis results of the topological complexity of the graph are as follows: average degree: 1.5, clustering coefficient: 0.0583, number of connected components: 6;
[0057] The statistical analysis results of path characteristics are as follows: average path length: 2.06, longest path: 4.
[0058] Step S3 is to construct an instruction generation intelligent agent based on the statistical analysis results of the knowledge graph, including constructing an intelligent agent planning module, an intelligent agent tool module, an intelligent agent storage module, and an intelligent agent execution module; specifically including,
[0059] Step S301, based on the statistical analysis results, construct an intelligent agent planning module to judge the category of the instruction pair to be generated and generate the corresponding inference planning path, including,
[0060] S3011: According to the classification status of single-round instructions, define different categories of specified pairs, including: seven forms of instruction categories such as inference, brainstorming, fixed Q&A, open Q&A, generation, summary, and role-playing;
[0061] S3012: Read the inference planning path prompt words from the intelligent agent storage module, call the large language model to judge the type of the instruction pair to be generated for the statistical analysis results of the knowledge graph, adopt the method of multi-plan inference planning path generation, and use different decoder sampling strategies to generate inference planning paths for different instruction categories, denoted as:
[0062] (Reasoning Step-1, Reasoning Step-2,..., Reasoning Step-n)
[0063] Reasoning Step-n represents the nth reasoning step.
[0064] Among them, the decoder sampling strategies include: temperature sampling, top-k sampling, and nucleus sampling. Temperature sampling adjusts the probability distribution of the model output through the temperature parameter. The larger the value, the smoother the distribution, and the more random the generated result. When the value is 0, it degenerates to greedy decoding; the principle of top-k sampling is that in each step of generation, only the k candidate words with the highest probabilities are retained, and the probabilities are renormalized among these k words and then sampled; nucleus sampling dynamically selects the smallest set of candidate words (referred to as the "nucleus") whose cumulative probability exceeds the threshold p, and the probabilities are renormalized within the nucleus and then sampled.
[0065] The basis for calling the large language model to judge the statistical analysis results of the knowledge graph is as follows: The reasoning category is applicable to triple chains with clear reasoning relationships (such as causality, hierarchy, etc.); the summarization category is applicable to triples that contain multiple facts or information points and require extracting key information from details; the role-playing category is applicable to triples that involve characters, scenarios, and environments.
[0066] S3013: Based on the reasoning planning paths generated by different sampling strategies, use the majority voting method to select the best reasoning planning path;
[0067] For example, in this embodiment, temperature sampling generates the reasoning type, top-k sampling generates the brainstorming type, and nucleus sampling generates the brainstorming type;
[0068] According to the majority voting principle, the reasoning type has 1 vote, and the brainstorming type has 2 votes. Therefore, it is determined that "brainstorming" is the most suitable instruction category, and the generated reasoning planning path is (brainstorming type, brainstorming type instruction generation, quality classification, instruction rewriting);
[0069] Step S302, construct the intelligent agent tool module to select the initial node, call the Neo4j graph database for knowledge graph exploration, and process the returned results to construct a triple chain containing entity, relationship, and structure information, which specifically includes the following steps:
[0070] S3021: Based on the constructed knowledge graph and the statistical analysis results to assist graph database query, based on the entity statistical analysis results of the knowledge graph and the importance analysis results of each node by LLMs, select the entity with the highest relevance as the initial node;
[0071] Entity statistical analysis results: The results of entity type statistical analysis are as follows: Organization: 8 times, Event: 13 times,..., Person: 3 times;
[0072] The results of entity occurrence frequency statistical analysis are as follows: Production and operation unit: 7 times, Work safety: 4 times,..., Society: 1 time.
[0073] The LLMs scoring results are as follows: Work safety: 4; Production and operation unit: 5;...; Government: 1; Society: 1;
[0074] Based on the above statistical analysis and scoring results, the "production and operation unit" has the highest score. Therefore, the key entity "production and operation unit" is obtained as the initial entity e. If the statistical analysis results are inconsistent with the scoring results, the entity with the highest occurrence frequency in the statistical analysis results is used as the initial entity e;
[0075] S3022: According to the initial entity e, the agent tool module calls the Neo4j graph database to obtain all the first-order neighbor entities of this entity and their relationships and stores them in the triple queue; the first-order neighbor entity refers to the entity directly connected to a certain central entity;
[0076] In this embodiment, the "production and operation unit" is passed as a parameter into the query statement, and all the first-order neighbor entities of the "production and operation unit" obtained are:
[0077] (Production and operation unit, responsible for, Work safety)...(Production and operation unit, responsible for, Improving work safety level)
[0078] Specifically, the query statement is the Cypher query statement: MATCH(n)-[r]->(m) WHERE n.value = $node_value RETURN n,r,m.
[0079] S3023: Read the triple queue in sequence, obtain the tail entity, and use the tail entity as the initial node to call the Neo4j graph database to explore all the first-order neighbors directly connected to this entity and their relationships again, and store them in the triple queue;
[0080] In this embodiment, the tail entity of the first triple obtained is "Work safety", and the first-order neighbors and their relationships explored with the tail entity as the initial node are:
[0081] (Work safety, aims at, Protecting people's lives and safety)...(Work safety, aims at, Adhering to safety first), and all triples are stored in the triple queue.
[0082] S3024: After reading the triple queue in sequence, merge the triples with the same entity to form a chain structure, denoted as:
[0083] (e, r 1,1 , e 1,1 , r 2,1 ,..., e m,n ), (e, r 1,2 , e 1,2 , r 2,1 ,..., e m,n ),...,(e, r 1,j , e 1,n , r 2,j ,..., e m,n )
[0084] r i,j represents the relationship of the j-th first-order neighbor node of the i-th entity, e m,n represents the n-th neighbor entity of the m-th relationship of the initial node e;
[0085] In this embodiment, after reading the triple queue, the triples with the same entity are merged into a chain structure, and the result is:
[0086] (The production and operation entity, is responsible for, work safety, aims at, protecting people's lives and safety,...)......(The production and operation entity, is responsible for, work safety, aims at, adhering to safety first,...).
[0087] Step S303, construct an agent storage module, which is divided into short-term storage and long-term storage. The triple information is used as short-term storage, and the prompt word templates of various tasks manually constructed (different category instruction generation tasks and instruction rewriting tasks) are used as long-term storage. There are the following types of information specifically:
[0088] (1) A triple chain containing entity, relationship, and structure information;
[0089] For example, in this embodiment, (The production and operation entity, is responsible for, work safety, aims at, protecting people's lives and safety,...)......(The production and operation entity, is responsible for, work safety, aims at, adhering to safety first,...).
[0090] (2) Inference planning path prompt words: Please generate an inference planning path for the instruction pair generation task based on the statistical analysis results of the input knowledge graph, which should include: 1. Carefully analyze the data characteristics and text content of the statistical analysis results of the knowledge graph; 2. Judge the most suitable instruction category; 3. Quality classification; 4. Instruction rewriting;
[0091] (3) Prompt words for generating instructions of the same category;
[0092] For example, the prompt word generated for the inference category instruction is: You are an instruction pair generator, and your task is to generate inference-based instruction pairs based on the triple chain and its underlying inference relationship. The generated data needs to have a certain reasoning ability, that is, complex.
[0093] (4) Quality classification prompt word: You are a quality classifier. Please classify the quality of the candidate instruction pairs according to the following evaluation indicators and their criteria. {Indicator 1}: {Criterion 1}, {Indicator 2}: {Criterion 2}. The following are some examples: {Example 1}, ……, {Example n};
[0094] (5) Instruction rewriting prompt word: I hope you act as an instruction pair rewriter. Your task is to rewrite the given candidate instruction pair into a more complex version, making it more difficult to process. However, the rewritten instruction pair must be reasonable, understandable and respondable by humans, and the original meaning of the instruction pair cannot be changed.
[0095] Step S304, construct an agent execution module for instruction generation, instruction rewriting, and instruction rewriting operations on unqualified data. Based on the inference planning path, first read the corresponding category of prompt word template from the agent storage module to perform the instruction generation operation, then read the corresponding category of quality classification prompt word from the agent storage module to evaluate and classify the quality of the instruction pair, and perform the instruction rewriting operation on the data with unqualified quality classification based on the classification result. The specific steps are as follows:
[0096] S3041: Instruction generation operation. Read the instruction generation prompt word corresponding to the category in the agent storage module and the currently stored triple chain, and use the large language model to generate the candidate instruction pair corresponding to the category.
[0097] In this embodiment, the brainstorming type instruction generation prompt word extracted from the agent storage module is input into the large language model to perform the instruction generation operation, and the generated data is:
[0098] {
[0099] “instruction”: “If a manufacturing enterprise within the territory of China fails to comply with the relevant regulations on work safety, fails to establish and improve the full-staff work safety responsibility system and work safety rules and regulations, and fails to conduct hierarchical control of safety risks and investigation and treatment of potential hazards, then what consequences can be inferred for this enterprise? Please explain in detail.”
[0100] “output”: “1. Legal liability: According to the first and fourth articles... 2. Economic losses: Due to the lack of effective safety management measures... 3. Reputation damage: The occurrence of production safety accidents... 4. Strengthened government supervision: The third article emphasizes... 5. Social supervision pressure: It is necessary to establish employee participation and government supervision...”
[0101] }
[0102] S3042: The agent performs a quality assessment and classification operation on the candidate instruction pair and outputs the result of the instruction quality assessment and classification as "Yes (qualified)" or "No (unqualified)", specifically including:
[0103] The specific method for classification is as follows: Manually construct a small number of quality classification examples of different categories, including positive and negative samples. Read the quality classification prompt words from the agent's storage module and pass the evaluation metrics, evaluation criteria, and their examples as parameters, and call the large language model to perform quality classification on the candidate instruction pair.
[0104] For example, the quality classification metrics and their criteria are:
[0105] Semantic ambiguity: Does the generated data have a clear meaning or is it ambiguous, resulting in multiple interpretations? Are there any terms or phrases that may confuse the model or the user due to unclear meaning?;
[0106] Logical error: Does the generated data have internal logical consistency? Are there any contradictions or incorrect inferences in the instruction that make it difficult for the model to follow?
[0107] In this embodiment, according to the inference planning path, read the brainstorming category prompt words from the agent's storage module, and use the above metrics for the agent to perform quality classification on the candidate instruction pair to determine whether the quality of the candidate instruction pair is "Yes (qualified)" or "No (unqualified)".
[0108] S3043: Based on the result of the instruction quality classification, perform an instruction rewriting operation on the unqualified instructions, including:
[0109] S30431: Based on the quality classification result, screen the candidate instruction pairs, and add the qualified instruction pairs corresponding to the candidate instruction pairs with the determined quality of "Yes" to the instruction dataset;
[0110] S30432: For unqualified instruction pairs, read the instruction rewriting prompt words from the agent's storage module;
[0111] S30433: According to the candidate instruction pair and the prompt words, perform a rewriting operation on the unqualified candidate instruction pair to optimize the expression of the instruction, make it more in line with the task requirements, have clearer logic, and more accurate information;
[0112] The process of the rewriting operation is as follows: Use the large language model to analyze the problems existing in the instruction pair, such as semantic ambiguity, logical error, knowledge inconsistency, etc.; read the instruction rewriting prompt words from the agent's storage module; the large language model performs appropriate rewriting operations according to the problem type, such as semantic rewriting, logical refinement, knowledge supplementation, etc.
[0113] S30434: Re-evaluate the rewritten candidate instruction pair.
[0114] For example, the generated candidate instruction pair is:
[0115] {
[0116] "instruction": "What is this law about?",
[0117] "output": "It is a law about safety."
[0118] }
[0119] If the quality classification of this instruction pair is "no", the agent execution module reads the prompting words for instruction rewriting from the agent storage module, and then performs the instruction rewriting operation. The rewritten instruction pair is:
[0120] {
[0121] "instruction": "Please elaborate on the main purposes and scope of application of the Work Safety Law, and explain the role it plays in promoting the safe development of enterprises and society.",
[0122] "output": "The main purpose of the Work Safety Law is to strengthen work safety, aiming to prevent and reduce the occurrence of work safety accidents, safeguard the lives and property of the people, and at the same time promote economic and social... It has established a comprehensive mechanism including employee participation, government supervision, industry self-discipline, and social supervision to enhance the overall work safety level and ensure work safety."
[0123] }
[0124] Thus, the complete process completes the construction of the instruction generation agent based on the knowledge graph.
[0125] In the embodiment of the present invention, the agent tool module is constructed by using the structural relationship of the knowledge graph to understand the logic and semantics in complex texts, focusing on the key information of the text to construct a triple chain as the context knowledge point, thereby enhancing the complexity and quality of the instruction pair; the agent planning module is constructed by adopting different sampling strategies to dynamically generate different types of inference planning paths, and using the majority voting strategy to select the most suitable instruction pair category and inference planning path; the agent storage module is used to store multi-task prompting words and the current triple chain information; in addition, an agent execution module is also constructed, which includes instruction generation operations and instruction rewriting operations, ensuring the diversity of instruction data categories while also ensuring the high quality of the generated instruction pairs, thereby obtaining a high-quality and diverse fine-tuning instruction set in an efficient and low-cost manner.
[0126] Embodiment 2
[0127] See Figure 2 , this embodiment provides a construction device for an instruction generation agent based on a knowledge graph, including
[0128] A knowledge graph construction module, which is used to obtain text, extract triples in the text and connect the triple data to a graph database, and construct a text knowledge graph based on a knowledge graph construction algorithm;
[0129] A knowledge graph statistical analysis module, which is used to statistically analyze the text knowledge graph from aspects of entities, relationships, and graph structures based on the text knowledge graph;
[0130] An instruction generation agent construction module, which is used to construct an instruction generation agent based on the statistical analysis results of the knowledge graph, including constructing an agent planning unit, an agent tool unit, an agent storage unit, and an agent execution unit; specifically:
[0131] The agent planning unit is used to judge the category of the instruction pair to be generated based on the statistical analysis results of the knowledge graph and generate a corresponding inference planning path;
[0132] The agent tool unit is used to select an initial node and call the graph database for knowledge graph exploration, and process the exploration return results to construct a triple chain containing entity, relationship, and structure information;
[0133] The agent storage unit is used to store data, including short-term storage and long-term storage. The short-term storage is used to store triple chain information, and the long-term storage is used to store prompt word templates for multiple tasks, including inference planning path prompt words, instruction generation prompt words for different categories, quality classification prompt words, and / or instruction rewriting prompt words;
[0134] The agent execution unit is used to, based on the inference planning path, read the instruction generation prompt words of the corresponding category and the currently stored triple chain from the agent storage module to execute the instruction generation operation, and read the quality classification prompt words of the corresponding category from the agent storage module to evaluate and classify the quality of the instruction pair, and perform an instruction rewriting operation on the data with unqualified quality classification based on the evaluation classification results.
[0135] Embodiment 3
[0136] The embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store a computer program related to a method in the method embodiment. The computer program is loaded and executed by the processor to implement the method provided in the above Embodiment 1.
[0137] Embodiment 4
[0138] An embodiment of the present invention further provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor, where when the processor executes the computer program, the method provided in Embodiment 1 above is implemented.
[0139] The description of the above embodiments is only used to help understand the method and its core idea of the present invention. It should be noted that for those of ordinary skill in the art of this technology, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
[0140] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs. The terms used in the description of the present invention in this specification are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0141] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of the steps can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the steps can be rearranged. The process can be terminated when its operation is completed, but there can also be additional steps not included in the drawings. The process can correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.
Claims
1. A method for constructing an instruction generation intelligent agent based on a knowledge graph, characterized in that, including obtaining text, extracting triples in the text and connecting the triple data to a graph database, and constructing a text knowledge graph based on a knowledge graph construction algorithm statistically analyzing the text knowledge graph from aspects of entities, relationships, and graph structures based on the text knowledge graph constructing an instruction generation agent based on the statistical analysis results of the knowledge graph, including constructing an agent planning module, an agent tool module, an agent storage module, and an agent execution module; specifically constructing an agent planning module based on the statistical analysis results of the knowledge graph to judge the category of the instruction pair to be generated and generate a corresponding inference planning path constructing an agent tool module, selecting an initial node and calling the graph database for knowledge graph exploration, processing the exploration return results, and constructing a triple chain containing entity, relationship, and structure information constructing an agent storage module, which is divided into short-term storage and long-term storage. The short-term storage is used to store triple chain information, and the long-term storage is used to store prompt word templates for various tasks, including inference planning path prompt words, instruction generation prompt words for different categories, quality classification prompt words, and / or instruction rewriting prompt words constructing an agent execution module, based on the inference planning path, reading the instruction generation prompt words of the corresponding category and the currently stored triple chain from the agent storage module to execute the instruction generation operation, and reading the quality classification prompt words of the corresponding category from the agent storage module to evaluate and classify the quality of the instruction pair, and performing an instruction rewriting operation on the data with unqualified quality classification based on the evaluation classification result 2. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 1, wherein, The obtaining text, extracting triples in the text and connecting the triple data to a graph database, and constructing a text knowledge graph based on a knowledge graph construction algorithm includes constructing knowledge graph schema information and extracting triples in the text according to the schema information connecting the extracted triple data to the graph database, creating nodes and edges through a knowledge graph construction algorithm and connecting them into a network. The knowledge graph construction method is a method including pattern-aware code hinting and principle enhancement 3. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 1, characterized in that, The statistically analyzing the text knowledge graph from aspects of entities, relationships, and graph structures based on the text knowledge graph includes statistically analyzing the entity type and the entity occurrence frequency based on the text knowledge graph statistically analyzing the relationship type and the relationship occurrence frequency based on the text knowledge graph statistically analyzing the topological complexity and path features of the graph based on the text knowledge graph, where the topological complexity includes the average degree, clustering coefficient, and number of connected components, and the path features include the average path length and the longest path 4. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 1, characterized in that The constructing an agent planning module based on the statistical analysis results of the knowledge graph to judge the category of the instruction pair to be generated and generate a corresponding inference planning path includes defining the specified pair type according to the classification status of the single-round instruction, including inference, brainstorming, fixed Q&A, open Q&A, generation, summary, and / or role-playing Read the inference planning path prompt from the agent storage module, and call the large language model to judge the type of the instruction pair to be generated based on the statistical analysis results of the knowledge graph. Adopt the method of multi-plan inference planning path generation, and use different decoder sampling strategies to generate inference planning paths of different instruction pair categories, denoted as: (Reasoning Step-1, Reasoning Step-2,..., Reasoning Step-n) where, ReasoningStep-n represents the nth reasoning step; Based on the inference planning paths generated by different sampling strategies, use the majority voting method to select the best inference planning path.
5. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 4, characterized in that, The decoder sampling strategies include temperature sampling, top-k sampling, and / or nucleus sampling.
6. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 1, characterized in that The construction of the agent tool module includes selecting the initial node and calling the graph database for knowledge graph exploration, and processing the exploration return results to construct a triple chain including entity, relationship, and structure information, Based on the constructed knowledge graph and the statistical analysis results of the knowledge graph, assist the graph database query. Utilize the statistical analysis results of the entities in the knowledge graph and the importance analysis results of each node by the large language model to select the entity with the highest relevance as the initial entity e; According to the initial entity e, call the graph database to obtain all first-order neighbor entities and their relationships of this entity and store them in the triple queue; Read the triple queue in sequence, obtain the tail entity, and use the tail entity as the initial node to call the graph database to explore all first-order neighbors directly connected to this entity and their relationships again with the same query statement, and store them in the triple queue; After reading the triple queue in sequence, merge the triples with the same entity to form a chain structure, denoted as: (e, r 1,1 , e 1,1 , r 2,1 ,..., e m,n ), (e, r 1,2 , e 1,2 , r 2,1 ,..., e m,n ),...,(e, r 1,j , e 1,n , r 2,j ,..., e m,n ) where, r i,j represents the relationship of the j-th first-order neighbor node of the i-th entity, e m,n represents the n-th neighbor entity of the m-th relationship of the initial node e.
7. The construction method of the instruction generation intelligent agent based on the knowledge graph according to claim 1, characterized in that, The instruction rewriting operation for the data with unqualified quality classification based on the evaluation classification results includes, Based on the quality classification results, screen the candidate instruction pairs, and add the qualified instruction pairs corresponding to the candidate instruction pairs with the judged quality of "qualified" to the instruction dataset; For unqualified instruction pairs, read the instruction rewriting prompt from the agent storage module; Determine the defect problems existing in the instruction data, including semantic ambiguity, logical error, and / or knowledge inconsistency; Select the corresponding rewriting method according to the type of defect problem, including semantic rewriting, logical refinement, and / or knowledge supplementation; Perform quality evaluation on the rewritten candidate instruction pairs again.
8. An apparatus for constructing an instruction generation intelligent agent based on a knowledge graph, characterized in that, Including, The knowledge graph construction module is used to obtain the text, extract the triples in the text and connect the triple data to the graph database, and construct the text knowledge graph based on the knowledge graph construction algorithm; The knowledge graph statistical analysis module is used to statistically analyze the text knowledge graph from aspects of entities, relationships, and graph structures based on the text knowledge graph; The instruction generation agent construction module is used to construct an instruction generation agent based on the statistical analysis results of the knowledge graph, including constructing an agent planning unit, an agent tool unit, an agent storage unit, and an agent execution unit; specifically: The agent planning unit is used to judge the category of the instruction pair to be generated based on the statistical analysis results of the knowledge graph and generate the corresponding inference planning path; An agent tool unit, which is used to select an initial node and call a graph database for knowledge graph exploration, and process the exploration return results to construct a triple chain containing entity, relationship, and structure information; An agent storage unit, which is used to store data, including short-term storage and long-term storage. The short-term storage is used to store triple chain information, and the long-term storage is used to store prompt word templates for multiple tasks, including inference planning path prompt words, different category instruction generation prompt words, quality classification prompt words, and / or instruction rewriting prompt words; An agent execution unit, which is used to generate instructions based on the inference planning path, read the corresponding category of instruction generation prompt words and the currently stored triple chain from the agent storage module to perform instruction generation operations, and read the corresponding category of quality classification prompt words from the agent storage module to evaluate and classify the quality of the instructions, and perform instruction rewriting operations on the data with unqualified quality classification based on the evaluation classification results.
9. A non-transitory computer-readable storage medium, characterized in that, A computer program is stored in the storage medium, and the computer program is loaded and executed by a processor to implement the construction method of the knowledge graph-based instruction generation agent according to any one of claims 1-7.
10. An electronic device, comprising: A processor, a memory, and a computer program stored on the memory and executable on the processor, wherein the processor implements the construction method of the knowledge graph-based instruction generation agent according to any one of claims 1-7 when executing the computer program.
Citation Information
Cited By
Method and device for navigation of body-equipped agent and electronic equipment
CN121275002A
Bridge management and maintenance knowledge graph construction method, system and equipment based on large-model multi-agent and medium
CN122047429A
Intelligent agent planning enhancement method based on knowledge graph
CN122132147A
Intelligent agent planning enhancement method based on knowledge graph
CN122132147B