Explainable Manufacturing Defect Investigation Using Knowledge Graphs, Neo4j GDS, MCP, and Agentic AI
A manufacturing investigation platform that combines Computer Vision outputs, Knowledge Graphs, Graph Data Science (GDS), Model Context Protocol (MCP), and Local LLM Agents to support defect analysis and engineering investigations.
The system extends traditional defect detection by providing contextual information, graph analytics, graph-based machine learning, and natural language access to manufacturing knowledge.
---
Overview
Traditional defect detection systems answer:
Is the product defective?
Quality engineers typically require additional context:
- Which machine produced it?
- Which supplier provided the materials?
- Have similar defects occurred before?
- Are there recurring defect patterns?
- What actions should be investigated?
This project combines manufacturing telemetry, traceability data, graph analytics, and LLM reasoning to generate explainable investigation reports.
---
System Architecture
AI4I Telemetry Dataset
+
MVTec Transistor Dataset
+
Synthetic Traceability Data
↓
Data Integration Pipeline
↓
Manufacturing Dataset
↓
Neo4j Knowledge Graph
↓
Neo4j Graph Data Science
↓
FastAPI + MCP Server
↓
LLM Investigation Agent
↓
Investigation Report
---
Core Components
Knowledge Graph
Manufacturing entities are represented as graph nodes.
Node Types
- ProductCase
- Machine
- Supplier
- Batch
- MaterialLot
- Operator
- Shift
- ProductionLine
- Defect
- FailureType
- Document
Relationships
(ProductCase)-[:PRODUCED_BY]->(Machine)
(ProductCase)-[:SUPPLIED_BY]->(Supplier)
(ProductCase)-[:BELONGS_TO_BATCH]->(Batch)
(ProductCase)-[:HAS_DEFECT]->(Defect)
(ProductCase)-[:EXHIBITS_FAILURE]->(FailureType)
(ProductCase)-[:WORKED_IN_SHIFT]->(Shift)
(ProductCase)-[:MENTIONED_IN]->(Document)
---
Graph Analytics
Implemented using Neo4j Graph Data Science.
PageRank Centrality
Identifies machines that are most influential within the manufacturing network.
Endpoint:
GET /analytics/centrality
Example Insight:
Machine M5 exhibits the highest centrality score.
---
Louvain Community Detection
Groups machines and suppliers with similar manufacturing behavior.
Endpoint:
GET /analytics/communities
Example Insight:
Machines and suppliers within the same community
share similar defect patterns.
---
Graph Machine Learning
Node Classification
Uses Neo4j GDS Node Classification Pipeline.
Workflow:
ProductCase Nodes
↓
FastRP Embeddings
↓
Logistic Regression
↓
Defect Classification
Training Endpoint:
POST /ml/train
Prediction Endpoint:
GET /ml/predict/{uid}
---
FastRP Embeddings
Generates graph embeddings for ProductCase nodes.
Endpoint:
POST /ml/embeddings
Embedding Size:
64 dimensions
Stored as:
pc.embedding
---
Similar Case Retrieval
Uses cosine similarity between FastRP embeddings.
Example:
MATCH (target:ProductCase)
MATCH (other:ProductCase)
WITH target, other,
gds.similarity.cosine(
target.embedding,
other.embedding
) AS similarity
Endpoint:
GET /ml/similar/{uid}
Purpose:
- Historical defect comparison
- Similar case retrieval
- Context-aware investigations
---
Text-to-Cypher
Natural language queries are converted into Cypher using a local LLM.
Example:
Which machines have the highest defect rates?
Generated Query:
MATCH ...
RETURN ...
Endpoint:
POST /text-to-cypher
---
Graph Builder
Documents can be ingested into the Knowledge Graph.
Supported Examples:
- Maintenance logs
- SOP documents
- Engineering reports
Endpoint:
POST /ingest-document
Generated Knowledge:
Machine
↓
MENTIONED_IN
↓
Document
---
MCP Investigation Agent
The MCP server exposes graph operations as tools.
Examples:
- get_case_context
- find_similar_cases
- calculate_machine_centrality
- detect_defect_communities
- text_to_cypher
The LLM agent invokes these tools to collect evidence and generate investigation reports.
---
Example Investigation Workflow
UID000001
↓
Retrieve Context
↓
Find Similar Cases
↓
Analyze Graph Patterns
↓
Collect Evidence
↓
Generate Investigation Report
Example Report Sections:
- Case Summary
- Evidence
- Hypothesis
- Recommendations
---
REST API
Data
POST /sync
---
Investigation
POST /investigate/{uid}
---
Graph Analytics
GET /analytics/centrality
GET /analytics/communities
---
Graph Machine Learning
POST /ml/train
POST /ml/embeddings
GET /ml/predict/{uid}
GET /ml/similar/{uid}
---
Knowledge Graph Querying
POST /text-to-cypher
---
Graph Builder
POST /ingest-document
---
Technology Stack
- FastAPI
- Neo4j
- Neo4j Graph Data Science
- MCP
- Ollama
- Qwen 2.5
- Python
- Docker
- PatchCore
- OpenCV
---
Project Goal
This project demonstrates how Knowledge Graphs, Graph Analytics, Graph Machine Learning, MCP, and LLM Agents can be combined to transform manufacturing defect detection into explainable manufacturing investigations.











