Overview
Digital Twins are live in-memory graphs of entities and relationships, initialized from ontologies and synchronized from storage. They enable real-time queries via SPARQL, ML-powered predictions, what-if scenarios, and automated actions. Key capabilities:- Entity Management: Store and query entities with attributes and relationships
- SPARQL Queries: Standard semantic queries on entity graphs
- ML Predictions: Run model inference on entity data
- What-If Scenarios: Test hypothetical changes
- Automated Actions: Trigger pipelines based on conditions
Digital Twin Structure
pkg/models/digitaltwin.go:10
Creating a Digital Twin
- curl
- Response
Synchronizing with Storage
Sync entities from storage backends:- Retrieve CIR data from configured storage backends
- Infer entity types from ontology classes
- Create or update entities with attributes
- Detect shared key fields across entity types
- Wire relationships based on matching key values
- Update
last_sync_attimestamp
Entity Resolution
When the same logical entity appears in multiple storage sources (e.g.,student_id=42 in both grades_db and attendance_db), records are merged into a single canonical entity:
pkg/digitaltwin/service.go:696
Relationship Wiring
After sync, entities with shared key field values are linked:pkg/digitaltwin/service.go:859
SPARQL Queries
Query entities using standard SPARQL syntax:SPARQL Examples
- List Entities
- Filter by Attribute
- Traverse Relationships
- Aggregate Functions
Running Predictions
Execute ML model predictions on entity data:Auto-Enrichment
Whenentity_id is provided, the service automatically enriches input features from related entities:
pkg/digitaltwin/service.go:386
Student entity with a related AttendanceRecord produces keys like:
avg_grade→ from Studentattendancerecord.days_absent→ from related AttendanceRecord
What-If Scenarios
Create hypothetical scenarios to test predictions:Automated Actions
Trigger pipelines when conditions are met:gt/gte— Greater than / or equallt/lte— Less than / or equaleq/ne— Equals / not equals
Updating Entities
Modify entity attributes (stored as delta modifications):Listing Entities
Best Practices
Sync Strategy
Sync Strategy
Auto-sync for real-time twins:Manual sync for controlled updates:Trigger sync via API when data changes.
Cache Configuration
Cache Configuration
Set TTLs based on data volatility:
- High volatility (1-5 min): Real-time sensor data
- Medium volatility (5-30 min): Customer profiles
- Low volatility (1+ hour): Product catalogs
Indexing Strategy
Indexing Strategy
- Lazy: Build indexes on first query (faster startup)
- Eager: Build indexes on sync (faster queries)
Scenario Management
Scenario Management
Archive old scenarios to prevent clutter:Keep only active what-if analyses.
Next Steps
ML Models
Train models for digital twin predictions.
Ontologies
Define entity types and relationships.
Storage
Configure data sources for sync.