Intelligent agent method for practical teaching based on ktp knowledge graph and enhanced retrieval
Patent Information
- Application Number
- CN202610922755.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-25
- Publication Date
- 2026-10-16
AI Technical Summary
纯向量语义检索将查询文本与节点文本映射至同一向量空间进行相似度匹配,能够有效处理单跳直接查询,但无法利用图谱的结构关系进行多跳遍历,对于涉及前置知识追溯、因果关系推理等多跳关联查询的召回能力严重不足
1.本发明通过构建KTP三层知识图谱本体模型,将实践教学知识抽象为知识层、任务层和问题层共12类实体,定义层内关系与跨层关系,并将实体与关系导入图数据库,实现了实践教学知识的结构化存储与显式关联建模。相较于纯大语言模型方案将知识隐含存储于模型参数中、推理过程不可追溯、知识来源无法验证的缺陷,本发明使所有知识及其关联关系以显式的图结构存储于图数据库中,推理路径可追溯、知识来源可验证,能够为学生提供结构化的诊断依据。同时,相较于传统以学科概念为中心的教育知识图谱,本发明通过知识层、任务层和问题层三层架构及跨层关系的定义,实现了从实践操作异常到根本原因的知识关联与追溯。
Smart Images

Figure CN122925634A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the interdisciplinary field of educational technology and artificial intelligence, specifically to a practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval. Background Technology
[0002] With the development of Large Language Model (LLM) technology, conversational teaching agents are increasingly being applied in practical teaching scenarios. Practical teaching typically involves programming training, experimental operations, and medical case analysis. Students generate a large number of natural language-based queries during the learning process, such as error analysis, prior knowledge retrieval, and operational step guidance. This provides ample opportunities for the application of teaching agents.
[0003] Currently, some technical solutions have attempted to directly apply large language models to practical teaching question-and-answer systems. However, pure large language model solutions implicitly store knowledge in model parameters, making the reasoning process untraceable. The knowledge source of the generated answers cannot be verified, making it difficult to provide students with structured diagnostic evidence. In practical teaching scenarios, this results in low credibility and poor interpretability.
[0004] In the field of educational knowledge graphs, existing technologies have proposed various methods for constructing knowledge graphs centered on subject concepts. These methods focus on the hierarchical relationships and semantic associations between concepts, and can support knowledge recommendation and concept retrieval to a certain extent. However, practical teaching scenarios are characterized by task-driven and problem-oriented approaches. Learners not only need to acquire declarative knowledge but also rely on cognitive understanding of operational procedures and reasoning judgments about the causes of anomalies. Traditional educational knowledge graphs lack explicit modeling of the three-layered association of "task steps - knowledge basis - incorrect solutions" in practical teaching scenarios, and cannot support automatic tracing from operational anomalies to their root causes.
[0005] In the field of Retrieval-Augmented Generation (RAG) technology, existing retrieval strategies are mainly divided into two categories: pure vector semantic retrieval and hybrid retrieval combining vector retrieval and graph traversal. Pure vector semantic retrieval maps query text and node text to the same vector space for similarity matching, which can effectively handle single-hop direct queries, but cannot utilize the structural relationships of the graph for multi-hop traversal. Its recall capability is severely insufficient for multi-hop related queries involving prior knowledge tracing and causal reasoning. While existing hybrid retrieval strategies attempt to introduce graph structure expansion, they generally use fixed weights to linearly weight semantic similarity scores and structural association scores. In single-hop direct query scenarios, the noise from neighboring nodes introduced by the expansion is too large, easily interfering with the ranking of highly relevant seed nodes. In multi-hop structural reasoning scenarios, the semantic scores of seed nodes suppress relevant nodes reachable through strong relationship paths, making it difficult for expanded results to enter the top rankings. These problems make it difficult for existing retrieval strategies to simultaneously meet the different needs of different query types for semantic matching and structural reasoning.
[0006] Therefore, there is an urgent need for a practical teaching agent method that integrates three-layer ontology structure modeling and graph-enhanced retrieval to solve problems such as the untraceability of reasoning caused by implicit knowledge storage, the lack of three-layer association modeling for practical teaching in traditional knowledge graphs, and the inability of existing retrieval strategies to take into account both single-hop direct query and multi-hop structural reasoning. Summary of the Invention
[0007] To overcome the shortcomings of existing technologies, the present invention aims to provide a practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval. This method stores practical teaching knowledge in an explicit graph structure, making reasoning paths traceable and knowledge sources verifiable. It can adaptively adapt retrieval strategies according to user query intent, enabling retrieval results to cover both semantic matching and structural association dimensions. Furthermore, it generates source-annotated answers through structured context constraints on a large language model, effectively suppressing model illusions and improving the interpretability of responses.
[0008] To achieve the objective of this invention, the following solution is adopted: The practical teaching agent method based on KTP knowledge graph and enhanced retrieval includes the following steps: Step S1: Construct a three-layer knowledge graph ontology model of KTP, abstract practical teaching knowledge into 12 types of entities in the knowledge layer, task layer and problem layer, define intra-layer relations and cross-layer relations, import entities and relations into the graph database, and obtain the KTP knowledge graph; Step S2: Receive user query, perform intent recognition on the user query, and classify the user query into knowledge recommendation, problem diagnosis or intelligent question answering categories to obtain intent classification results; Step S3: Based on the KTP knowledge graph, the user query, and the intent classification results, perform an enhanced retrieval three-stage hybrid retrieval to obtain the names and structured contexts of the first K nodes; Step S4: Inject the structured context into the system prompt words of the large language model, and require the large language model to generate an answer based on the structured context and label the source node to obtain a practical teaching intelligent answer based on knowledge graph enhanced retrieval.
[0009] Furthermore, in step S1, the 12 types of entities include: concepts, principles, methods, and rules in the knowledge layer; tasks, steps, products, and evaluation criteria in the task layer; and problems, solutions, tools, and cases in the problem layer.
[0010] Furthermore, in step S1, intra-layer relationships include preceding, related, containing, following, generating, being evaluated, resolving, using, and referencing; cross-layer relationships include needing and causing.
[0011] Furthermore, in step S2, the intent recognition is performed by combining a rule-based fast channel with a zero-shot classification channel of a large language model: A preset keyword-intent mapping table is constructed. When the keyword in the user query matches the mapping table, the corresponding intent classification result is directly output through the rule fast channel. If the keyword in the user query does not match the mapping table, the large language model is called to output the intent classification result through the large language model zero-shot classification channel.
[0012] Furthermore, in step S3, the enhanced retrieval three-stage hybrid retrieval specifically includes: Call the full-text index of the graph database to obtain the top N candidate nodes that match the literal text of the user's query, and obtain the candidate node set; The user query text and the names and descriptions of each candidate node are vector-encoded using a vector embedding model. Cosine similarity is calculated, and the top K nodes with the highest similarity are selected as seed nodes to obtain a set of seed nodes. Starting from the various child nodes in the seed node set, extend the neighbor set by 1 hop along the specified relationship type to obtain the neighbor node set; perform adaptive scoring and intent-aware weighting on each neighbor node in the neighbor node set; sort the seed node set and the neighbor node set globally according to the final score, and output the names and structured contexts of the top K nodes after seed protection processing.
[0013] Furthermore, the adaptive scoring and intent-aware weighting specifically include: Calculate the semantic similarity score between all seed nodes in the seed node set and the user query text, and take the highest value S_max; If S_max ≥ the first threshold T1, it is determined as a single-hop query, the seed node is assigned a first structure bonus B_seed=B1, and the neighbor node is assigned a second structure bonus B_neighbor=B2; If S_max < T1, it is determined as a multi-hop query, the seed node is assigned a third structure bonus B_seed=B3, and the neighbor node is assigned a fourth structure bonus B_neighbor=B4; Infer the target relation type set R_focus corresponding to the query intention according to the keywords in the user query text, and for the neighbor nodes reached through the relation types in R_focus, an additional fifth structure bonus B_focus=B5 is assigned in the multi-hop query scenario, otherwise B_focus=0; The calculation formula for the final scores of the seed node and the neighbor node is as follows: score_final(s) = sim(q, s) + B_seed score_final(n) = sim(q, n) + B_neighbor + B_focus Wherein, sim(q,s) is the semantic similarity between the seed node s and the query q, and sim(q,n) is the semantic similarity between the neighbor node n and the query q; B_seed and B_neighbor take values according to the relationship between S_max and T1; B_focus takes values according to whether the relation type on the arrival path of the neighbor node belongs to R_focus.
[0014] Further, the inference rule for the target relation type set R_focus is: When the user query contains error, malfunction or problem, R_focus is the cause relation type; When the user query contains precondition, prerequisite or basis, R_focus is the prepositive relation type; When the user query contains solve, repair or troubleshoot, R_focus is the resolution relation type.
[0015] Further, outputting the names of the top K nodes and their structured context after the seed guarantee processing specifically includes: Performing global descending sorting on the seed node set and the neighbor node set according to the final scores, and taking the top K nodes as the output set; Checking whether the output set contains at least one seed node; If the intersection of the output set and the seed node set is empty, the seed node with the highest final score is replaced to the Kth position of the output set to obtain the corrected output set, ensuring that the final returned result contains at least one semantic seed node; Sort the search results in descending order of the final score, and output the names and structured contexts of the top K nodes.
[0016] Furthermore, in step S4, the core constraint of the prompt words in the structured context injection large language model system is: Answers should be based on the context of the retrieved knowledge graph. Fabricating content that does not appear in the context is prohibited, and key knowledge points must be labeled with the source node name.
[0017] Furthermore, the formula for calculating the cosine similarity is as follows: sim(q, c) = (v_q · v_c) / (||v_q|| × ||v_c||) Where v_q represents the vector embedding of the user query text q, v_c represents the vector embedding of the name and description text of the candidate node c, · represents the vector dot product, and ||·|| represents the L2 norm of the vector.
[0018] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. This invention constructs a three-layer KTP knowledge graph ontology model, abstracting practical teaching knowledge into 12 types of entities across the knowledge layer, task layer, and problem layer. It defines intra-layer and cross-layer relationships and imports these entities and relationships into a graph database, achieving structured storage and explicit relational modeling of practical teaching knowledge. Compared to pure large language model solutions that implicitly store knowledge in model parameters, have untraceable reasoning processes, and lack verifiable knowledge sources, this invention stores all knowledge and its relationships in an explicit graph structure within a graph database. Reasoning paths are traceable, and knowledge sources are verifiable, providing students with structured diagnostic evidence. Furthermore, compared to traditional educational knowledge graphs centered on subject concepts, this invention, through its three-layer architecture (knowledge, task, and problem layers) and the definition of cross-layer relationships, achieves knowledge association and tracing from practical operational anomalies to their root causes.
[0019] 2. This invention identifies user query intent before retrieval, categorizing queries into knowledge recommendation, problem diagnosis, or intelligent question answering types. The intent classification results are then used as input for subsequent retrieval, enabling enhanced retrieval to adaptively adjust its focus based on different query intents, thus improving the targeting and accuracy of the search. Compared to existing technologies that use a uniform processing method for all queries, this invention precisely categorizes different types of practical teaching questions through intent classification, avoiding interference from irrelevant knowledge and improving retrieval efficiency and answer quality.
[0020] 3. This invention integrates the advantages of multiple retrieval strategies by performing a three-stage hybrid retrieval enhanced search. Compared to the shortcomings of pure vector semantic retrieval, which relies solely on semantic matching and cannot utilize graph structure relationships, this invention combines the graph structure expansion capabilities of graph databases on the basis of semantic retrieval. This allows the retrieval results to not only cover knowledge nodes semantically similar to the query text, but also structurally related nodes reachable through knowledge graph relationship paths, thereby improving the knowledge coverage of the retrieval results.
[0021] 4. This invention injects the retrieved structured context into the system prompts of a large language model, requiring the large language model to generate answers based on the retrieved knowledge graph context and label the source nodes. This effectively improves the credibility and interpretability of the large language model's answers in practical teaching scenarios. Compared to pure large language model solutions that rely entirely on parameterized knowledge to generate answers and cannot trace the reasoning process, this invention constrains the model's generation process through structured context, ensuring that the generated answers have clear knowledge sources. Furthermore, each key knowledge point is labeled with the source node name, facilitating knowledge tracing and verification by students. This significantly enhances the practicality and credibility of the teaching agent in practical teaching scenarios. Attached Figure Description
[0022] Figure 1 This is a flowchart of the practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of the KTP three-layer knowledge graph ontology in an embodiment of the present invention; Figure 3 A schematic diagram of the intent recognition process in an embodiment of the present invention.
[0023] Figure 4 This is a flowchart of the GraphRAG three-stage hybrid retrieval in an embodiment of the present invention; Figure 5 This is a logic diagram of the adaptive scoring mechanism in an embodiment of the present invention; Figure 6 This is a schematic diagram of the overall architecture of the practical teaching intelligent agent system based on KTP knowledge graph and enhanced retrieval in an embodiment of the present invention. Detailed Implementation
[0024] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments. It should be noted that, without conflict, the various embodiments or technical features described below can be arbitrarily combined to form new embodiments.
[0025] This invention provides a practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval, which can be widely applied to teaching scenarios of various practice-oriented courses, including but not limited to programming practice teaching, hospital information system course teaching, medical statistics course teaching, etc., to realize knowledge recommendation, problem source diagnosis and intelligent question answering in practical teaching.
[0026] like Figure 1 As shown in the figure, the practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to an embodiment of the present invention includes the following steps: Step S1: Construct a three-layer knowledge graph ontology model of KTP, abstract practical teaching knowledge into 12 types of entities in knowledge layer, task layer and problem layer, define intra-layer relations and cross-layer relations, import entities and relations into graph database to obtain KTP knowledge graph; Step S2: Receive user query, perform intent recognition on the user query, and classify the user query into knowledge recommendation, problem diagnosis or intelligent question answering categories to obtain intent classification results; Step S3: Based on the KTP knowledge graph, the user query, and the intent classification results, perform an enhanced retrieval three-stage hybrid retrieval to obtain the names and structured contexts of the first K nodes; Step S4: Inject the structured context into the system prompt words of the large language model, and require the large language model to generate an answer based on the structured context and label the source node to obtain a practical teaching intelligent answer based on knowledge graph enhanced retrieval.
[0027] The practical teaching agent method based on KTP knowledge graph and enhanced retrieval, as described in the embodiments of the present invention, will be further elaborated below.
[0028] The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to embodiments of the present invention is detailed as follows: A three-layer KTP knowledge graph ontology model was constructed. For the target practical teaching courses, course knowledge was abstracted into 12 entity types and 11 relation types across a knowledge layer, task layer, and problem layer. The entities and relations were then imported into the graph database Neo4j. The target courses include, but are not limited to, programming courses, medical information system courses, medical statistics courses, and various experimental and practical training courses.
[0029] Receive user queries and perform intent recognition. Receive natural language queries input by students, and perform intent recognition using a combination of rule-based fast-track and LLM zero-shot classification, classifying the queries into knowledge recommendation, problem diagnosis, or intelligent question answering categories.
[0030] Perform a three-stage hybrid GraphRAG search. Sort the search results in descending order of the final score and output the names and structured contexts of the top K nodes.
[0031] Knowledge-enhanced response generation. The retrieved structured context is injected into the LLM's system prompts. The LLM is required to generate answers based on the retrieved knowledge graph context. Fabricating content that does not appear in the context is prohibited, and key knowledge points must be labeled with the source node name.
[0032] In some embodiments, the GraphRAG three-stage hybrid retrieval step specifically includes: Phase 1 calls the graph database's built-in full-text index to retrieve the top N candidate nodes that match the literal text of the query text; In Phase 2, the Embedding model is used to vectorize the query text and the names and descriptions of each candidate node, calculate the cosine similarity, and select the top K nodes with the highest similarity as seed nodes. Phase 3 starts from the seed node, expands one-hop neighbors along the specified relation type, performs semantic filtering and relation weighted scoring on the expanded neighbor nodes, and returns the top K results after global sorting by the final score. During the third phase of expansion, based on the relationship between the highest semantic similarity score between the seed node and the query text and the preset threshold, the system adaptively determines whether to perform a single-hop direct query or a multi-hop structural reasoning query, and assigns different structural bonuses to the seed node and its neighbor nodes respectively. At the same time, the system infers the set of target relation types based on the keywords in the query text, and assigns additional structural bonuses to neighbor nodes reached through the target relation types in the multi-hop scenario. In the first K results after global sorting, if no seed node exists, the seed node with the highest score is replaced in the Kth position, ensuring that the final returned results contain at least one semantic seed node. The search results are then sorted in descending order of final score, and the names and structured contexts of the first K nodes are output.
[0033] The practical teaching agent method based on KTP knowledge graph and enhanced retrieval in this invention has the following advantages: 1. This invention achieves structured storage of practical teaching knowledge through a three-layer KTP ontology model, unifying and formalizing the knowledge layer, task layer, problem layer, and their cross-layer relationships, thus solving the problems of implicit knowledge storage and untraceable reasoning paths in pure LLM solutions. 2. This invention integrates the advantages of full-text retrieval, vector semantic retrieval, and graph structure expansion through a three-stage hybrid GraphRAG retrieval system. In single-hop query scenarios, GraphRAG performs similarly to pure vector retrieval; in multi-hop query scenarios, GraphRAG significantly improves the recall capability of relevant nodes through graph structure expansion. 3. This invention balances single-hop direct query and multi-hop structural reasoning through an adaptive scoring mechanism. In single-hop queries, seed nodes with high semantic matching are protected; in multi-hop queries, neighbor competition is relaxed, allowing strong relationship expansion nodes to have a chance to enter the Top-K results. 4. This invention significantly improves the recall rate in multi-hop query scenarios by assigning extra structural scores to specific relationships such as CAUSES, PREREQUISITE, and SOLVES through query intent-aware relationship weighting. In PREREQUISITE multi-hop queries, GraphRAG achieves a Recall@3 of 0.42, significantly outperforming the 0.08 of pure vector retrieval. 5. This invention ensures the reliability of retrieval results through a seed node protection mechanism, avoiding the situation where all seed nodes are squeezed out of the Top-K by neighboring nodes in multi-hop scenarios.
[0034] like Figure 1 As shown below, the process of the practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval according to an embodiment of the present invention will be described in detail.
[0035] In this embodiment, in step S1, as follows Figure 2 As shown, it specifically includes: Step S1.1: Define the knowledge layer entity types, including Concept, Principle, Method, and Rule.
[0036] Step S1.2: Define the entity types of the task layer, including Task, Step, Artifact, and Criterion.
[0037] Step S1.3: Define the problem layer entity types, including Problem, Solution, Tool, and Case.
[0038] Step S1.4: Define the relationships within the layer, including PREREQUISITE, RELATED_TO, CONTAINS, FOLLOWS, PRODUCES, EVALUATED_BY, SOLVES, USES, and REFERENCES.
[0039] Step S1.5: Define cross-layer relationships, including REQUIRES (knowledge required for the task) and CAUSES (problems caused by knowledge deficiencies or task errors); import the above entities and relationships into the Neo4j graph database to form a KTP three-layer knowledge graph.
[0040] In this embodiment, in step S2, as follows Figure 3 As shown, it specifically includes: Step S2.1: Construct a rule quick channel: Preset keyword-intent mapping table, and directly output the corresponding intent type when the query text matches the keyword.
[0041] Step S2.2: If the rule channel is not matched, call LLM to perform zero-sample classification and classify the query into knowledge recommendation, problem diagnosis or intelligent question answering.
[0042] Step S2.3: Output intent type label as input for subsequent retrieval strategies.
[0043] In this embodiment, in step S3, as follows Figure 3 and Figure 4 As shown, it specifically includes: Step S3.1, Phase 1 FULLTEXT Candidate Recall: Call the built-in full-text index of the Neo4j graph database, input the query text q, and return the set of the top N candidate nodes that match the literal meaning of the query text C={c_1, c_2, ..., c_N}, where N is 50.
[0044] Step S3.2, Stage Two Vector Semantic Ranking: Using the Embedding model, the query text q and the "name + description" text of each candidate node are vector-encoded to obtain the query vector v_q and the node vector v_c. The cosine similarity is calculated using the following formula: sim(q, c) = (v_q · v_c) / (||v_q|| × ||v_c||) Where v_q represents the embedding vector of query text q, v_c represents the embedding vector of the "name + description" text of candidate node c, · represents the vector dot product, and ||·|| represents the L2 norm of the vector.
[0045] Step S3.3: Select the top K nodes with the highest cosine similarity in the candidate set C as the seed node set S={s_1, s_2, ..., s_K}, where K is 3.
[0046] Step S3.4: Third-stage graph structure expansion: Starting from each node in the seed node set S, expand 1-hop neighbors along specified relationship types such as CAUSES, REQUIRES, SOLVES, and PREREQUISITE to obtain a neighbor node set N={n_1, n_2, ..., n_m}.
[0047] Step S3.5: Adaptive scoring and intent-aware weighting: Calculate the semantic similarity scores of all nodes in the seed node set S with the query text, and take the maximum value S_max=max{sim(q, s_i) | s_i ∈ S}; if S_max ≥ the first threshold T1 (T1=0.7), it is determined as a single-hop direct query, the seed nodes are assigned a first structure bonus B_seed=B1 (B1=0.4), and the neighbor nodes are assigned a second structure bonus B_neighbor=B2 (B2=0.2); if S_max < T1, it is determined as a multi-hop structure inference query, the seed nodes are assigned a third structure bonus B_seed=B3 (B3=0.1), and the neighbor nodes are assigned a fourth structure bonus B_neighbor=B4 (B4=0.8); meanwhile, the target relationship type set R_focus is inferred according to the keywords in the query text: when the query contains "error", "fault", "problem", R_focus={CAUSES}; when the query contains "preposition", "prerequisite", "basis", R_focus={PREREQUISITE}; when the query contains "solve", "repair", "troubleshoot", R_focus={SOLVES}; for neighbor nodes reached through the relationship types in R_focus, an additional fifth structure bonus B_focus=B5 (B5=0.6) is assigned in the multi-hop query scenario, otherwise B_focus=0.
[0048] The final score calculation formula for the above seed nodes and neighbor nodes is as follows: score_final(s) = sim(q, s) + B_seed score_final(n) = sim(q, n) + B_neighbor + B_focus Where sim(q,s) is the semantic similarity between seed node s and query q, and sim(q,n) is the semantic similarity between neighbor node n and query q; B_seed and B_neighbor are determined according to the relationship between S_max and T1 according to the S3.5 rule; B_focus is determined according to the relationship type on the path to neighbor node and whether it belongs to R_focus according to the S3.5 rule.
[0049] Step S3.6, Global Sorting and Seed Node Guarantee: Sort the seed node set S and the neighbor node set N globally in descending order according to the final score_final, and take the top K nodes as the output set O; check whether the output set O contains at least one seed node; if O ∩ S = ∅, then replace the seed node s* with the highest score_final(s) to the Kth position of O to obtain the corrected output set O', ensuring that the final returned result contains at least one semantic seed node.
[0050] In some embodiments, taking a C programming course as an example, it specifically includes: Knowledge layer entity extraction: Based on the C language textbook, the teaching team organized the knowledge hierarchy structure and extracted Concept entities such as variables, arrays, and pointers; Principle entities such as the pass-by-address principle; Method entities such as binary search; and Rule entities such as identifier naming rules. A total of 185 knowledge layer entities were extracted.
[0051] Task-level entity extraction: Programming problems are exported from the Online Judge platform, and the sequence of task steps is extracted using a large language model. For example, the task "Implement linked list insertion operation" extracts the following steps: create a new node → assign data fields → adjust pointer pointers. A total of 83 Task entities and 595 Step entities were extracted.
[0052] Problem-level entity extraction: Problem-solution pairs are summarized from student error records. For example, the problem "pointer lost" corresponds to the solution "introduce a temporary pointer to save the address of the successor node". A total of 65 Problem entities and 196 Solution entities were extracted.
[0053] Relationship construction: Define 9 types of intra-layer relations (such as PREREQUISITE, CONTAINS, SOLVES, etc.) and 2 types of cross-layer relations (REQUIRES, CAUSES). All data is imported into the Neo4j graph database, and the final knowledge base has 1341 nodes and 2229 relations.
[0054] The entity structure of the knowledge graph is shown in Table 1, and the relation structure is shown in Table 2.
[0055] Table 1 Knowledge Graph Entity Structure Table 2 Knowledge Graph Relationship Structure In some embodiments, taking the query "What errors will occur when learning linked lists" as an example, the execution process of GraphRAG three-stage hybrid retrieval in a single-hop scenario is illustrated, specifically including: FULLTEXT Candidate Recall: Call Neo4j full-text index, input query text "What errors will occur when learning linked lists", and return N=50 candidate nodes, including "linked list" (Concept), "linked list insertion" (Task), "pointer loss" (Problem), "memory leak" (Problem), "empty linked list handling" (Case), etc.
[0056] Vector semantic ranking: Baidu Qianfan Embedding-V1 is used for 384-dimensional vector encoding, and the cosine similarity between the query text and the names and descriptions of each candidate node is calculated. The top K=3 seed nodes are selected: linked list (0.82), linked list deletion (0.61), and empty linked list processing (0.58).
[0057] Graph structure expansion: Starting from the seed node "linked list", expand by 1 hop along the CAUSES, REQUIRES, SOLVES, PREREQUISITE relationship to obtain neighbor node pointer loss (via CAUSES), memory leak (via CAUSES), structure (via PREREQUISITE), linked list insertion (via REQUIRES), etc.
[0058] Adaptive scoring: The highest score of the seed node, S_max = 0.82, is greater than the threshold T1 = 0.7, thus it is determined to be a single-hop scenario. Seed bonus B_seed = B1 = 0.4, and neighbor bonus B_neighbor = B2 = 0.2. The query contains "error" or "problem," R_focus = {CAUSES}, but since this is a single-hop scenario, the B5 bonus is not triggered. The final score for each node is calculated as follows: Linked list: 0.82 + 0.4 = 1.22; Pointer lost (neighbor, via CAUSES): sim(query, pointer lost) + 0.2 = 0.45 + 0.2 = 0.65; Memory leak (neighbor, via CAUSES): sim(query, memory leak) + 0.2 = 0.38 + 0.2 = 0.58.
[0059] The top 3 results are returned after global sorting: linked list, lost pointer, and memory leak. This example verifies that in a single-hop scenario, the seed node reliably occupies the Top-1 position thanks to the B1 score, while the CAUSES neighbor nodes enter the Top-K position thanks to the B2 score, covering the common error types of interest to the query.
[0060] In some embodiments, taking the query "prerequisite knowledge for learning structures" as an example, the adaptive scoring process in a multi-hop scenario is illustrated. Specifically, it includes: FULLTEXT candidate recall returns N=50 candidate nodes, including structures, linked lists, pointers, arrays, functions, etc.
[0061] The vector semantic sorting selects the first K=3 seed nodes: structure (0.55), structure variable (0.48), and structure array (0.42).
[0062] Graph structure expansion: Starting from the "structure", expand by 1 hop to obtain pointers (via PREREQUISITE), arrays (via PREREQUISITE), typedefs (via RELATED_TO), etc.
[0063] Adaptive scoring: In step S3.5, the highest score of the seed node, S_max = 0.55, is less than the threshold T1 = 0.7, and is therefore determined to be a multi-hop scenario. The seed node receives a bonus of B3 = 0.1, and the neighbor node receives a bonus of B4 = 0.8. If the query contains "preceding", R_focus = {PREREQUISITE}, an additional bonus of B5 = 0.6 is awarded.
[0064] Final scores for each node: Structure: 0.55 + 0.1 = 0.65; Pointer (neighbor, via PREREQUISITE, hits R_focus): sim(query, pointer) + 0.8 + 0.6 = 0.48 + 1.4 = 1.88; Array(neighbors, via PREREQUISITE, hit R_focus): sim(query, array) + 0.8 + 0.6 = 0.42 + 1.4 = 1.82.
[0065] The top 3 are sorted globally: pointers (1.88), arrays (1.82), and structs (0.65). The seed node "struct" is retained in the Top-3 and does not require triggering a safety net mechanism.
[0066] This example demonstrates that in a multi-hop scenario, by using high neighbor score B4 and intent-aware score B5, "pointer" and "array", which originally had low semantic similarity, successfully entered the Top-3 thanks to the PREREQUISITE structured relationship, effectively covering the multi-hop association knowledge that vector retrieval could not recall.
[0067] In some embodiments, taking the query "What to do if the array is out of bounds" as an example, the knowledge-enhanced response generation is specifically implemented as follows: GraphRAG retrieval returned the following Top-3 nodes: array out of bounds (Problem, score=0.91), boundary condition check (Solution, score=0.72), and one-dimensional array (Concept, score=0.68).
[0068] The structured context is injected into the LLM system's prompts, with the core constraint: "Answer based on the retrieved knowledge graph context; fabrication of content not appearing in the context is prohibited; key knowledge points must be labeled with the source node name." The LLM-generated answer states: "Array out of bounds occurs when accessing an array element whose index exceeds the array's valid range (Source: Array Out of Bounds). Solutions include: adding boundary condition checks before array access to ensure the index value is between 0 and the array length minus 1 (Source: Boundary Condition Check). For one-dimensional arrays, special attention needs to be paid to the initialization and termination conditions of loop variables (Source: One-Dimensional Array)."
[0069] The answer is generated based on the retrieval context, and all knowledge points are labeled with the source node name, which effectively suppresses model illusion and improves the interpretability and traceability of the response.
[0070] In some embodiments, taking a C programming course as an example, 38 sets of test queries were designed for comparative experiments, divided into six categories: single-hop - error reporting (7 sets), single-hop - knowledge (6 sets), CAUSES multi-hop (8 sets), PREREQUISITE multi-hop (6 sets), SOLVES multi-hop (5 sets), and cross-layer reverse (6 sets). Three strategies were compared: FULLTEXT (pure full-text retrieval), Vector (pure vector semantic retrieval), and GraphRAG (the three-stage hybrid retrieval proposed in this invention). Two evaluation metrics were used: Recall@3: The proportion of relevant nodes in the returned Top-3 results to the total number of relevant nodes in the query, reflecting the retrieval's ability to cover relevant knowledge; MRR (Mean Reciprocal Rank): The reciprocal mean of the positions of related nodes in the sorting results, reflecting the sorting quality.
[0071] Relevance is determined using bidirectional substring matching: if the returned node name and the expected query answer have a bidirectional substring inclusion relationship, it is determined to be relevant. Experimental results for different scenarios are shown in Table 3. Table 3 Comparison of Search Performance by Scenario Experimental results show that: 1. In single-hop query scenarios, the performance differences among the three strategies are small. In single-hop error queries, the three strategies perform similarly (FULLTEXT 0.52, Vector 0.55, GraphRAG 0.58) because the error name has a high literal match with the keyword. In single-hop knowledge queries, FULLTEXT's Recall@3 is 0.50, lower than Vector's 0.58, because there is a semantic difference between "learn pointers" and "pointer," which pure literal matching cannot cover; GraphRAG has a Recall@3 of 0.60 and an MRR of 0.72, similar to Vector's performance, indicating limited gains from graph expansion.
[0072] 2. In CAUSES multi-hop queries, FULLTEXT's Recall@3 is only 0.10 because there is no literal match between "list" and "pointer lost"; Vector improves to 0.25; GraphRAG reaches 0.42 through CAUSES relational extension, with an MRR of 0.55.
[0073] 3. In PREREQUISITE multi-hop queries, FULLTEXT's Recall@3 is only 0.05, which is almost impossible to recall; Vector's is 0.08; GraphRAG achieves 0.42 through high neighbor bonus B4 and intent-aware bonus B5, with an MRR of 0.63, verifying the significant advantage of the adaptive scoring mechanism in multi-hop pre-knowledge queries.
[0074] 4. In SOLVES multi-hop queries, FULLTEXT has a Recall@3 of 0.08; Vector has a Recall@3 of 0.20; GraphRAG achieves a Recall@3 of 0.35 and an MRR of 0.52 through SOLVES relation expansion. This is mainly due to the fact that graph expansion enables solution nodes that cannot be directly recalled by vector retrieval to enter the Top-K.
[0075] 5. In cross-layer reverse lookup, FULLTEXT's Recall@3 is only 0.05, making it completely impossible to traverse across layers; Vector's is 0.12; GraphRAG achieves 0.38 through reverse REQUIRES relationship expansion, with an MRR of 0.48.
[0076] In summary, GraphRAG maintains performance comparable to pure vector retrieval in single-hop scenarios, and achieves significant improvements in recall and ranking quality in multi-hop and cross-layer query scenarios through graph structure expansion and adaptive scoring mechanisms.
[0077] like Figure 5 As shown in the figure, an embodiment of the present invention also provides a practical teaching intelligent agent system based on KTP knowledge graph and enhanced retrieval, including: The knowledge graph construction module is used to execute step S1, construct the KTP three-layer knowledge graph ontology model, abstract practical teaching knowledge into 12 entity types in total, including knowledge layer, task layer and problem layer, define 9 types of intra-layer relations and 2 types of cross-layer relations, and import the entities and relations into the graph database Neo4j. The intent recognition module is used to execute step S2, receive the natural language query input by the student, and perform intent recognition by combining rule fast channel with LLM zero-shot classification, classifying the query into knowledge recommendation, problem diagnosis or intelligent question answering. The GraphRAG retrieval module is used to execute step S3, which involves a three-stage hybrid retrieval process, including stage one full-text candidate recall, stage two vector semantic ranking, and stage three graph structure expansion. During stage three expansion, an adaptive scoring and intent-aware weighting submodule is integrated. It determines single-hop or multi-hop query scenarios based on the highest semantic similarity score and assigns corresponding structural bonuses. Simultaneously, it infers the target relationship type based on query keywords and applies intent-aware weighting to neighboring nodes. A global ranking and seed protection submodule is also included, which globally ranks the expanded nodes and ensures that the Top-K results contain at least one semantic seed node. The response generation module is used to perform step S4, which injects the retrieved structured context into the system prompt words of the large language model, and requires the generation of answers based on the context and the labeling of source nodes.
[0078] This invention also provides a practical teaching intelligent agent device based on KTP knowledge graph and enhanced retrieval, comprising: at least one processor; at least one memory for storing at least one program; when the at least one program is executed by the at least one processor, the at least one processor implements the steps of the practical teaching intelligent agent method based on KTP knowledge graph and enhanced retrieval as described in this invention. The processor may be a central processing unit (CPU), graphics processing unit (GPU), tensor processing unit (TPU), or other dedicated AI acceleration chip. The memory includes a non-transient computer-readable storage medium, such as random access memory (RAM), read-only memory (ROM), flash memory, solid-state drive (SSD), or hard disk drive (HDD).
[0079] This invention also provides a storage medium storing processor-executable instructions, which, when executed by a processor, implement the steps of the practical teaching agent method based on KTP knowledge graph and enhanced retrieval as described in this invention. The storage medium includes, but is not limited to: magnetic storage media (such as hard disks and magnetic tapes), optical storage media (such as CD-ROMs and DVDs), semiconductor storage media (such as USB flash drives, SD cards, and SSDs), and network-based cloud storage services.
[0080] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.
Claims
1. A practical teaching agent method based on KTP knowledge graph and enhanced retrieval, characterized in that, Includes the following steps: Step S1: Construct a three-layer knowledge graph ontology model of KTP, abstract practical teaching knowledge into 12 types of entities in knowledge layer, task layer and problem layer, define intra-layer relations and cross-layer relations, import entities and relations into graph database to obtain KTP knowledge graph; Step S2: Receive user queries, perform intent recognition on the user queries, and classify the user queries into knowledge recommendation, problem diagnosis, or intelligent question answering categories to obtain intent classification results; Step S3: Based on the KTP knowledge graph, the user query, and the intent classification results, perform an enhanced retrieval three-stage hybrid retrieval to obtain the names and structured contexts of the first K nodes; Step S4: Inject the structured context into the system prompt words of the large language model, and require the large language model to generate an answer based on the structured context and label the source node to obtain a practical teaching intelligent answer based on knowledge graph enhanced retrieval.
2. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 1, characterized in that, In step S1, the 12 types of entities include: concepts, principles, methods and rules in the knowledge layer; tasks, steps, products and evaluation criteria in the task layer; and problems, solutions, tools and cases in the problem layer.
3. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 1, characterized in that, In step S1, intra-layer relationships include preceding, related, containing, following, generating, being evaluated, resolving, using, and referencing; cross-layer relationships include needing and causing.
4. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 1, characterized in that, In step S2, the intent recognition is performed by combining a rule-based fast channel with a large language model zero-shot classification channel: Construct a preset keyword-intent mapping table. When the keywords in the user's query match the mapping table, directly output the corresponding intent classification result through the rule fast channel. If the keywords in the user query do not match the mapping table, the large language model is invoked to output the intent classification result through the zero-shot classification channel of the large language model.
5. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 1, characterized in that, In step S3, the enhanced retrieval three-stage hybrid retrieval specifically includes: Call the full-text index of the graph database to obtain the top N candidate nodes that match the literal text of the user's query, and obtain the candidate node set; The user query text and the names and descriptions of each candidate node are vector-encoded using a vector embedding model. Cosine similarity is calculated, and the top K nodes with the highest similarity are selected as seed nodes to obtain a set of seed nodes. Starting from the various child nodes in the seed node set, extend the neighbor set by 1 hop along the specified relationship type to obtain the neighbor node set; perform adaptive scoring and intent-aware weighting on each neighbor node in the neighbor node set; sort the seed node set and the neighbor node set globally according to the final score, and output the names and structured contexts of the top K nodes after seed protection processing.
6. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 5, characterized in that, The adaptive scoring and intent-aware weighting specifically include: Calculate the semantic similarity score between all seed nodes in the seed node set and the user query text, and take the highest value S_max; If S_max ≥ the first threshold T1, it is determined to be a single-hop query. The seed node is given a first structural score B_seed=B1, and the neighbor node is given a second structural score B_neighbor=B2. If S_max < T1, it is determined as a multi-hop query, a third structure bonus point B_seed=B3 is assigned to the seed node, and a fourth structure bonus point B_neighbor=B4 is assigned to the neighbor node; Infer the target relationship type set R_focus corresponding to the query intent according to the keywords in the user query text, and for the neighbor nodes reached through the relationship types in R_focus, a fifth structure bonus point B_focus=B5 is additionally assigned in the multi-hop query scenario, otherwise B_focus=0; The formula for calculating the final scores of the seed node and the neighbor node is as follows: score_final(s) = sim(q, s) + B_seed score_final(n) = sim(q, n) + B_neighbor + B_focus Wherein, sim(q,s) is the semantic similarity between the seed node s and the query q, sim(q,n) is the semantic similarity between the neighbor node n and the query q; B_seed and B_neighbor take values according to the relationship between S_max and T1; B_focus takes a value according to whether the relationship type on the arrival path of the neighbor node belongs to R_focus.
7. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 6, characterized in that, The inference rule for the target relationship type set R_focus is: When the user query contains error, fault or problem, R_focus is the cause relationship type; When the user query contains precondition, prerequisite or basis, R_focus is the pre-relationship type; When the user query contains solve, repair or troubleshoot, R_focus is the resolution relationship type.
8. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 5, characterized in that, Outputting the names of the top K nodes and their structured contexts after the seed guarantee processing specifically includes: Performing a global descending sort on the seed node set and the neighbor node set according to the final scores, and taking the top K nodes as the output set; Checking whether the output set contains at least one seed node; If the intersection of the output set and the seed node set is empty, the seed node with the highest final score is replaced to the K-th position of the output set to obtain a corrected output set, so as to ensure that the final returned result contains at least one semantic seed node; Sorting the retrieval results in descending order of the final scores, and outputting the names and structured contexts of the top K nodes.
9. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 1, characterized in that, In the step S4, the core constraint for injecting the structured context into the large language model system prompt is: Answer based on the retrieved knowledge graph context, it is forbidden to fabricate content that does not appear in the context, and key knowledge points must be marked with the source node name.
10. The practical teaching agent method based on KTP knowledge graph and enhanced retrieval according to claim 5, characterized in that, The calculation formula of the cosine similarity is as follows: sim(q, c) = (v_q · v_c) / (||v_q|| × ||v_c||) Wherein, v_q represents the vector embedding of the user query text q, v_c represents the vector embedding of the name and description text of the candidate node c, · represents the vector dot product, and ||·|| represents the L2 norm of the vector.