A numerical control machine tool fault diagnosis method and system based on a knowledge graph and a large language model

By combining knowledge graphs and large language models in the fault diagnosis method, the problems of semantic alignment difficulties and potential missing associations in CNC machine tool fault diagnosis are solved, achieving efficient and accurate fault analysis and decision-making, and improving the diagnostic effect in complex fault scenarios.

CN122432279APending Publication Date: 2026-07-21HUAZHONG UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAZHONG UNIV OF SCI & TECH
Filing Date
2026-04-03
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing technologies for fault diagnosis of CNC machine tools suffer from problems such as semantic alignment difficulties, missing potential associations, and lagging knowledge evolution, making it difficult to effectively uncover the deep-seated potential relationship between alarm phenomena and fault causes, especially in complex fault scenarios where the diagnostic effect is poor.

Method used

A fault diagnosis method based on knowledge graphs and large language models is adopted. The user input is transformed into a structured representation through the large language model. Candidate entities are selected by combining semantic similarity and domain rules in the knowledge graph, a few-shot prompt is constructed and chain reasoning is performed to generate answers in natural language form. The accuracy of the answers is ensured by knowledge graph consistency verification.

Benefits of technology

It significantly improves the completeness and reasoning accuracy of knowledge graphs, effectively uncovers hidden connections, enhances the comprehensiveness and accuracy of fault diagnosis, reduces the risk of unreliable answers, possesses self-correction capabilities, and adapts to fault analysis and decision-making under complex working conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122432279A_ABST
    Figure CN122432279A_ABST
Patent Text Reader

Abstract

The application belongs to the field of intelligent diagnosis of industrial equipment, and particularly discloses a numerical control machine tool fault diagnosis method and system based on a knowledge graph and a large language model, which comprises: using a large language model for query analysis LLM-R, logical reasoning LLM-I and answer generation verification LLM-E respectively, and combining the structured knowledge retrieval and verification capability of the knowledge graph, a chain question and answer method is formed. Specifically, LLM-R is used to analyze user queries, and candidate entities and context subgraphs are obtained by combining the knowledge graph; LLM-I is used to construct a few-shot prompt guide model to carry out chain reasoning to generate a reasoning chain; finally, LLM-E generates a natural language answer and carries out consistency verification through the knowledge graph to output the final result. The application can deeply mine the hidden association between the numerical control machine tool alarm phenomenon and the fault cause, greatly improve the completeness and reasoning accuracy of the knowledge base, and improve the fault diagnosis effect under complex working conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of intelligent diagnosis of industrial equipment, and more specifically, relates to a method and system for diagnosing faults in CNC machine tools based on knowledge graphs and large language models. Background Technology

[0002] With the widespread application of CNC machine tools in manufacturing, a large amount of fault cases and alarm data have accumulated during long-term operation. Currently, engineers' knowledge of fault diagnosis mainly relies on personal experience, and this knowledge is mostly stored in unstructured forms, such as maintenance logs, text records, or verbal summaries, exhibiting significant dispersion and subjectivity. This form of knowledge leads to problems such as inconsistent expression and misunderstandings, making it difficult to achieve effective inheritance, sharing, and reuse.

[0003] In recent years, knowledge graphs (KG) have been introduced into the field of industrial intelligent diagnostics. By structuring experiential knowledge in the form of triples (e.g., "alarm-phenomenon-cause-countermeasure"), they effectively support the querying and logical reasoning of fault knowledge. By modeling equipment components, fault types, cause analysis, and maintenance plans as entities and relationships, the graph can form multi-level semantic associations, enabling the systematic accumulation and machine-readable representation of experiential knowledge. However, the following are the main challenges in the actual construction of knowledge graphs: 1. Semantic alignment difficulties: Different engineers describe the same fault in different ways, making it difficult to achieve entity standardization and relationship unification; 2. Missing potential connections: The graph structure is severely incomplete, and many implicit relationships (such as cross-device common causes, indirect causes, etc.) have not been modeled, which limits the reasoning ability in complex fault scenarios; 3. Lagging knowledge evolution: New types of fault phenomena and patterns emerge frequently, and traditional map update methods are unable to respond in a timely manner.

[0004] To address the problem of incomplete knowledge maps, academia and industry have proposed various knowledge completion methods, mainly including: 1. Structural embedding methods (such as TransE and CompGCN): These methods predict relationships by embedding existing graph triples into models. While these methods are fast inference methods, they struggle to capture semantic details, especially when dealing with low-frequency (long-tail) entities.

[0005] 2. Text augmentation methods (such as KG-BERT and StAR): These methods combine pre-trained language models to model the semantics of entity descriptions, enhancing reasoning capabilities. While improving accuracy, these methods are highly dependent on training resources, and the cost of migrating to new graphs is significant.

[0006] 3. Few-shot learning methods (such as MetaR and GANA): These methods introduce meta-learning and graph neural networks to address the problem of scarce training samples. However, they are sensitive to path selection, have low stability, and limited generalization ability.

[0007] In summary, existing methods still have significant shortcomings in semantic understanding, long-tail entity recognition, and complex path reasoning. Particularly in the typical high-dimensional sparse knowledge scenario of CNC machine tool fault diagnosis, they struggle to fully uncover the deep-seated potential relationships between "alarm-phenomenon-cause-countermeasure." Therefore, there is an urgent need for a method that integrates language understanding and knowledge reasoning capabilities to overcome existing technological bottlenecks, improve the completeness of knowledge graphs and diagnostic reasoning abilities, and achieve intelligent and interpretable fault analysis and decision-making. Summary of the Invention

[0008] In view of the above-mentioned defects or improvement needs of existing technologies, this invention provides a CNC machine tool fault diagnosis method and system based on knowledge graph and large language model. Its purpose is to deeply explore the hidden correlation between CNC machine tool alarm phenomena and fault causes, and improve the fault diagnosis effect under complex working conditions.

[0009] To achieve the above objectives, according to one aspect of the present invention, a fault diagnosis method for CNC machine tools based on knowledge graphs and large language models is proposed, comprising the following steps: The user input describing CNC machine tool faults is transformed into a structured representation using a large language model; based on the semantic similarity between the structured user input and entities in the knowledge graph, as well as domain rules, entities are filtered to obtain candidate entities and their context subgraphs. Based on the candidate entities and context subgraph, a few-shot hint is constructed and a chain reasoning template is injected into it. The few-shot hint is input into the large language model, and the chain reasoning template guides the large language model to perform chain reasoning, thereby evaluating and ranking the candidate entities based on the few-shot hint and generating a complete reasoning chain. By generating natural language expressions for the reasoning chain using a large language model, the answer output in natural language form is obtained, thus completing the fault diagnosis.

[0010] As a further preferred embodiment, the few-sample prompt specifically includes: role setting and task definition; user input question, candidate entities and their context subgraphs; question-answering and reasoning process examples; and predefined chain reasoning templates.

[0011] As a further preferred method, the method for obtaining the question-answering and reasoning process examples is as follows: based on the current question, candidate entities and their context subgraphs, select several example question-answer pairs from the historical case library to form question-answering and reasoning process examples.

[0012] As a further optimization, after obtaining the answer in natural language form, the answer is checked for consistency with the knowledge graph to ensure that the reasoning content of the answer does not conflict with the known facts in the knowledge graph, and then the answer is output.

[0013] As a further optimization, when verifying the consistency between the answer and the knowledge graph, if the answer is found to contain content that does not conform to the known facts in the knowledge graph, error correction feedback is generated, triggering the large language model to adjust the reasoning process or correct the few-sample prompts, and then re-reasoning to obtain the corrected answer output.

[0014] As a further preferred approach, determining candidate entities includes the following steps: First, based on the user's input topic, a preliminary query is performed in the knowledge graph to obtain relevant entities; the relevant entities and relationships, as well as the structured user input, are represented as vector A and vector B, respectively; based on the semantic similarity of vector A and vector B and domain rules, the relevant entities are filtered to obtain candidate entities and their context subgraphs.

[0015] As a further preferred approach, the relevant entities and relationships, as well as the structured user input, are represented as vectors using the RotatE embedding algorithm.

[0016] As a further preferred embodiment, the knowledge graph is constructed based on Neo4j.

[0017] As a further optimization, after completing the fault diagnosis, the knowledge graph is updated based on the answer.

[0018] According to another aspect of the present invention, a fault diagnosis system for CNC machine tools based on knowledge graphs and large language models is provided, comprising a knowledge retrieval module LLM-R, a reasoning and decision-making module LLM-I, and a result generation module LLM-E constructed based on a large language model, wherein: The knowledge retrieval module LLM-R transforms user input describing CNC machine tool faults into a structured representation using a large language model; it then filters entities based on the semantic similarity between the structured user input and entities in the knowledge graph, as well as domain rules, to obtain candidate entities and their context subgraphs. The reasoning and decision-making module LLM-I constructs few-shot hints based on candidate entities and context subgraphs, and injects chain reasoning templates into them; the few-shot hints are input into the large language model, and the chain reasoning templates guide the large language model to perform multi-step reasoning similar to CoT, thereby evaluating and ranking candidate entities based on few-shot hints and generating a complete reasoning chain; The LLM-E module generates natural language expressions for the inference chain using a large language model, outputting the answer in natural language form to complete fault diagnosis.

[0019] In summary, compared with the prior art, the above-described technical solutions conceived by this invention mainly possess the following technical advantages: 1. This invention utilizes the deep semantic construction and generative reasoning capabilities of Large Language Models (LLM), combined with the structured knowledge and constrained reasoning capabilities of knowledge graphs, to effectively uncover hidden associations between CNC machine tool alarm phenomena and fault causes that are missed in the knowledge graph without relying on a large amount of additional training. This significantly improves the completeness and reasoning accuracy of the knowledge graph, thereby significantly improving the fault diagnosis effect under complex working conditions.

[0020] 2. This invention cleverly applies Prompt learning to the candidate generation and inference processes, effectively introducing the prior knowledge and generalization ability of the large model. Through few-shot examples and chained reasoning, it improves the model's reasoning performance in complex fault scenarios. Simultaneously, the knowledge graph provides factual evidence to constrain the inference direction of the large model, avoiding unfounded speculation and ensuring that the reasoning process is based on evidence. This "dual-intelligence fusion" mechanism of language model and knowledge graph enables the system to uncover implicit connections that are difficult to discover using traditional methods, improving the comprehensiveness and accuracy of fault diagnosis.

[0021] 3. By setting up a knowledge graph consistency check, the system ensures that the final answer output to the user is consistent with the known knowledge in the knowledge graph at both the logical and factual levels, significantly reducing the risk of unreliable answers (such as false facts or logical errors) generated by the large language model. Furthermore, it automatically iterates and adjusts itself once an answer is detected to be inconsistent with the knowledge graph, demonstrating self-correction capabilities.

[0022] 4. Compared to single-model solutions, this invention employs a multi-LLM division of labor to make each stage of the system more targeted: LLM-R focuses on information retrieval to accelerate candidate recall, LLM-I focuses on deep reasoning to ensure decision accuracy, and LLM-E is responsible for result presentation and verification to ensure output reliability. Through the collaborative architecture of multiple LLMs, the system significantly improves its coverage of long-tail fault knowledge and the stability of complex reasoning while maintaining high efficiency. Attached Figure Description

[0023] Figure 1 This is a schematic diagram of the framework of the CNC machine tool fault diagnosis method based on knowledge graph and large language model according to an embodiment of the present invention. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0025] This invention provides a CNC machine tool fault diagnosis system based on knowledge graphs and large language models, such as... Figure 1 As shown, the system comprises three modules based on the Qwen large language model: a knowledge retrieval module (LLM-R) for knowledge retrieval, a reasoning and decision-making module (LLM-I) for reasoning and decision-making, and a result generation module (LLM-E) for result generation and verification. These three modules perform their respective functions based on different prompt templates, collaborating layer by layer to discover and verify fault associations. The Neo4j knowledge graph is used for storing and retrieving structured knowledge. Details are as follows: The knowledge retrieval module LLM-R receives user input and transforms the user's query into a structured representation based on natural language parsing. It then performs an initial retrieval of relevant entity nodes in the knowledge graph. In conjunction with the RotatE embedding model, it represents both relevant entities and structured input as vectors. It then combines domain rules and semantic similarity mechanisms to filter high-quality candidate entities and constructs a context subgraph based on the candidate entities, providing a structured knowledge background for subsequent reasoning.

[0026] The LLM-I inference decision-making module automatically constructs a Few-shot Prompt based on candidate entities and context subgraphs, and injects fault analogy examples and inference templates to guide LLM-I in performing chain-of-thought multi-step inference. During inference, the model evaluates and ranks the credibility of candidate entities based on strategies such as instance analogy, context alignment, and entity inference, generating a complete inference chain and reasoning basis.

[0027] The LLM-E module generates natural language representations from the LLM-I output and performs consistency checks with the knowledge graph to ensure that the reasoning content does not conflict with known facts in the knowledge graph. If a conflict is found, a feedback adjustment and re-reasoning mechanism is triggered; if the verification passes, the final completed result and explanation are output as the answer.

[0028] The specific functions of the above diagnostic system are explained in the subsequent diagnostic methods section and will not be repeated here.

[0029] This invention provides a method for diagnosing CNC machine tool faults based on knowledge graphs and large language models, comprising the following steps: Step 1: Query parsing and knowledge retrieval (LLM-R).

[0030] The system uses a structured engine and an LLM-R model to parse user-input natural language queries, extracting structured information such as key entities, relationships, and intents. Relevant knowledge is then retrieved from the Neo4j knowledge graph to filter candidate entities and their context subgraphs. Specifically, this includes: First, LLM-R generates a corresponding structured representation based on the user's output, such as transforming complex questions into query formats understandable by the knowledge graph (e.g., Cypher statements or triples). Utilizing the structured retrieval capabilities of the Neo4j graph database, relevant entities matching the query topic are initially obtained. The query topic refers to the entity type corresponding to the entity extracted from the input text at the knowledge graph ontology layer.

[0031] Subsequently, the RotatE embedding algorithm is introduced to pre-vectorize relevant entities and relationships in the knowledge graph, and the structured user query is also represented as a vector to calculate its semantic similarity with each relevant entity. By combining semantic similarity matching and domain rule filtering, relevant entities are semantically filtered, removing entities irrelevant or ambiguous to the query and retaining the most relevant candidate entities. Domain rules refer to whether the entity types and relationship combinations in the knowledge graph conform to predefined constraints.

[0032] Finally, using these selected candidate entities as seeds, a contextual subgraph (including the candidate entity, its associated relationships, and neighboring entities) is extracted from the knowledge graph to support subsequent reasoning. This step transforms a natural language problem into a structured retrieval task and obtains a knowledge graph subgraph closely related to the semantics of the problem, providing an accurate knowledge foundation for subsequent steps.

[0033] By using LLM-R and a knowledge graph engine for collaborative parsing, we can leverage the semantic understanding capabilities of large language models to obtain accurate query intents, while utilizing the embedding retrieval capabilities of knowledge graphs to locate relevant entities and their relational subgraphs. Furthermore, by integrating RotatE-based vector semantic matching into the traditional knowledge graph retrieval process, we can improve the relevance and recall of retrieval results.

[0034] Step 2: Prompt Assembly and Chained Reasoning (LLM-I).

[0035] After obtaining candidate entities and their context subgraphs, the inference phase begins. This step utilizes the LLM-I model combined with the knowledge context to construct a Few-shot Prompt and performs Chain-of-Thought (CoT) reasoning to generate a complete inference chain. Specifically, this includes: First, based on the content of the context subgraph and the question type, several example question-answer pairs are selected from the historical case library to form examples of question-answering and reasoning processes, which are used to demonstrate how to use knowledge graph information to gradually reason for the answer. Specifically, Sentence-BERT can be used to semantically encode the current input text to form a vector; the cosine similarity between this vector and the historical case library is calculated, and the cases with the highest similarity (example question-answer pairs) are selected to inject hints.

[0036] This is then assembled into a Few-shot Prompt, which includes: 1) role setting and task definition; 2) several question-and-answer and reasoning process examples; 3) user input questions, candidate entities and their context subgraphs; and 4) predefined chain reasoning templates.

[0037] By embedding a chain-like reasoning template within the Prompt, LLM-I is guided to generate a step-by-step reasoning process in a chain-like manner. During this process, LLM-I integrates facts provided by the context subgraph, simulating multi-hop reasoning by human experts to derive intermediate conclusions until a solution is formed. It is important to emphasize that the Prompt's design ensures that LLM-I has sufficient knowledge support while adhering to the logic of example reasoning, thus innovatively guaranteeing the coherence and interpretability of the reasoning process. While generating the reasoning chain, LLM-I also produces references to the knowledge graph nodes or relationships upon which each step of reasoning is based, providing a basis for subsequent result verification.

[0038] Through these steps, LLM-I will generate a series of logically connected reasoning steps under the guidance of the Prompt, including problem analysis, intermediate reasoning processes, and preliminary answers derived from the knowledge graph. This chain-like reasoning process improves the model's accuracy in answering complex questions and makes the intermediate reasoning steps transparent and traceable.

[0039] Step 3: Result generation and consistency verification (LLM-E).

[0040] After reasoning is completed, the LLM-E module generates the answer in natural language and verifies its consistency using a knowledge graph. Specifically, this includes: Extract the final conclusion or preliminary answer from the LLM-I chain reasoning, as well as the key knowledge graph facts referenced during the reasoning process; LLM-E then refines the answer, generating a fluent and professional natural language response. Simultaneously, it cross-checks the facts in the answer against the knowledge graph to ensure consistency between the answer and the knowledge in the context subgraphs.

[0041] For example, if the answer involves the attribute value of an entity or the relationship between two entities, LLM-E will verify the statement based on the context subgraph. If the answer is found to contain content that does not conform to the knowledge of the graph, LLM-E can be used to generate error correction feedback, triggering adjustments to the reasoning process or corrections to the Prompt, and re-reasoning to obtain a corrected answer.

[0042] In one implementation, consistency verification involves parsing the answer text generated by LLM-E and matching the entities and relationships involved with the context subgraph. In another implementation, an "validation prompt" can be designed to be performed by LLM-E, allowing the model to self-check whether each point of the answer is supported by a provided list of knowledge graph triples.

[0043] The above steps ensure that the consistency verification mechanism is effectively implemented: the model-generated answers are not only grammatically correct, but each key argument is also supported by data from the knowledge graph. If a discrepancy is detected between the answer and the knowledge graph, the system will automatically iterate and adjust, demonstrating its self-correcting capabilities.

[0044] The knowledge graph is then updated and supplemented for subsequent question-and-answer queries. First, new entities, relations, and attributes are extracted and converted into triples. Next, entity alignment and disambiguation are performed, matching and merging new knowledge with existing graph nodes or creating new nodes to avoid data redundancy. Finally, the updated data is formally written into the Neo4j graph database and the retrieval index is rebuilt synchronously, ensuring that subsequent question-and-answer queries can instantly access these latest knowledge links.

[0045] To make the present invention clearer, a specific example of a small sample prompt is given below: [Character Setting] You are an experienced CNC machine tool diagnostic engineer with the ability to read diagram structures and perform step-by-step analogical reasoning.

[0046]

Task Definition

[0047] Input Structure 1. Current query description: Alarm number: <e.g., ALM-011> Observed phenomena: <e.g., "Z-axis stops running, driver reports an error"> 2. Initial Context Subgraph (OCS): Query entity: e_h = <e.g., "Z-axis" or "ALM-011"> Related entity nodes: {Entity 1, Entity 2, ...} Relationship path set (format: Entity A -> Relation -> Entity B): [R1, R2, ... 3. Supplement the context subgraph (SCS): Candidate tail entity set (T'): {entity A, entity B, ...} Candidate path context: T_i<-R1-...-Rk<- e_h (path form) 4. Example of historical reasoning process (optional): Example alarm and background description example using subgraph relationship chains (reference graph paths) Example reasoning chain and final judgment [Reasoning Task Guide] Please perform the following reasoning task and output the sorting results and explanation process: ① Identify the system state expressed by the alarm number (e.g., "ALM-011 -> indicates -> servo driver overcurrent") ② Extract the structure, function, and abnormal nodes directly related to the queried entity from the OCS. ③ Evaluate the causal path confidence between each candidate entity and the original query from the SCS (e.g., lubrication system failure -> jamming -> abnormal current). ④ Perform pattern matching and analogy analysis by referring to similar reasoning chains in historical examples (if any). ⑤ Output a sorted list of candidate tail entities (potential root causes), with each item supporting the spectral path. ⑥ Summarize the reasoning process using natural language for domain personnel to verify and understand. Output format specifications Step-by-step reasoning chain (graph path): Example: ALM-011 -> Indicates -> Overcurrent <- Cause <- Ball screw jamming <- Cause <- Lubrication system failure The sorted list of candidate root causes (each labeled graph supports path and confidence score). Suggested order of investigation (considering the relationships in the graph and the system structure) Natural Language Interpreted Text (Clearly structured, easy to review) [Conformity Verification Requirements] (To be called by subsequent system modules) Please ensure that your inference chain does not conflict with the graph facts in OCS / SCS. If there are path contradictions or logical inconsistencies, please indicate and adjust them in the output.

[0048] In summary, this invention utilizes a series of large language models for query parsing, logical reasoning, and answer generation and verification, combined with the structured knowledge retrieval and verification capabilities of knowledge graphs, to form a chain-based question-answering method. Through modular division of labor and collaboration, it fully leverages the semantic understanding and generative reasoning capabilities of large language models, as well as the structured knowledge and constrained reasoning capabilities of knowledge graphs. This invention has the following innovative aspects: 1) It introduces semantic retrieval embedded in knowledge graphs, improving the accuracy of query-related knowledge retrieval; 2) It designs a Few-shot Prompt combined with a chain-based reasoning template to guide the large language model to provide an interpretable reasoning process; 3) It adds a consistency verification step based on knowledge graphs to ensure the credibility and correctness of the answers. These technical features work together to effectively overcome the problems of insufficient semantic understanding, opaque reasoning chains, and unreliable answers in existing large language models for knowledge question answering, significantly improving the performance and reliability of knowledge question answering systems. Especially when dealing with novel or complex fault scenarios, it can rely on a complete knowledge graph and chain reasoning to obtain more accurate root cause analysis and handling solutions, providing strong technical support for intelligent operation and maintenance decision-making of CNC machine tools, and fully demonstrating the practical value of this invention in the field of industrial fault diagnosis.

[0049] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A numerical control machine tool fault diagnosis method based on a knowledge graph and a large language model, characterized by, Includes the following steps: The user input describing CNC machine tool faults is transformed into a structured representation using a large language model; based on the semantic similarity between the structured user input and entities in the knowledge graph, as well as domain rules, entities are filtered to obtain candidate entities and their context subgraphs. Based on candidate entities and context subgraphs, construct few-sample hints and inject chained reasoning templates into them; The few-shot prompts are input into the large language model, and the chain reasoning template guides the large language model to perform chain reasoning, thereby evaluating and ranking candidate entities based on the few-shot prompts and generating a complete reasoning chain. By generating natural language expressions for the reasoning chain using a large language model, the answer output in natural language form is obtained, thus completing the fault diagnosis.

2. The knowledge graph and large language model-based numerical control machine tool fault diagnosis method of claim 1, wherein, The few-sample prompts specifically include: role setting and task definition; user input questions, candidate entities and their context subgraphs; question-answering and reasoning process examples; and predefined chain reasoning templates.

3. The CNC machine tool fault diagnosis method based on knowledge graphs and large language models as described in claim 2, characterized in that, The method for obtaining the question-and-answer and reasoning process examples is as follows: based on the current question, candidate entities and their context subgraphs, select several example question-and-answer pairs from the historical case library to form question-and-answer and reasoning process examples.

4. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in claim 1, characterized in that, After obtaining the answer in natural language form, the answer is checked for consistency with the knowledge graph to ensure that the reasoning in the answer does not conflict with the known facts in the knowledge graph, and then the answer is output.

5. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in claim 4, characterized in that, When verifying the consistency between the answer and the knowledge graph, if the answer contains content that does not conform to the known facts in the knowledge graph, error correction feedback is generated, triggering the large language model to adjust the reasoning process or correct the few-sample prompts, and then re-reasoning to obtain the corrected answer output.

6. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in claim 1, characterized in that, Determining candidate entities involves the following steps: First, based on the user's input topic, a preliminary query is performed in the knowledge graph to obtain relevant entities; the relevant entities and relationships, as well as the structured user input, are represented as vector A and vector B, respectively; based on the semantic similarity of vector A and vector B and domain rules, the relevant entities are filtered to obtain candidate entities and their context subgraphs.

7. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in claim 6, characterized in that, The RotatE embedding algorithm is used to represent relevant entities and relationships, as well as structured user input, as vectors.

8. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in claim 1, characterized in that, The knowledge graph is built on Neo4j.

9. The CNC machine tool fault diagnosis method based on knowledge graph and large language model as described in any one of claims 1-8, characterized in that, After completing the fault diagnosis, the knowledge graph is updated based on the answer.

10. A fault diagnosis system for CNC machine tools based on knowledge graphs and large language models, characterized in that, It includes the knowledge retrieval module LLM-R, the reasoning and decision-making module LLM-I, and the result generation module LLM-E, all built on a large language model. The knowledge retrieval module LLM-R transforms user input describing CNC machine tool faults into a structured representation using a large language model; it then filters entities based on the semantic similarity between the structured user input and entities in the knowledge graph, as well as domain rules, to obtain candidate entities and their context subgraphs. The reasoning and decision-making module LLM-I constructs few-shot hints based on candidate entities and context subgraphs, and injects chain reasoning templates into them; the few-shot hints are input into the large language model, and the chain reasoning templates guide the large language model to perform multi-step reasoning similar to CoT, thereby evaluating and ranking candidate entities based on few-shot hints and generating a complete reasoning chain; The LLM-E module generates natural language expressions for the inference chain using a large language model, outputting the answer in natural language form to complete fault diagnosis.