Concepts
Graph Health
SmartMemory measures the structural health of your knowledge graph through metrics like orphan ratio, provenance coverage, and type distribution.
Health Metrics
GraphHealthChecker
Collects health metrics via Cypher queries:
| Metric | Description | Healthy Threshold |
|---|---|---|
total_nodes | Number of nodes in the graph | — |
total_edges | Number of edges in the graph | — |
orphan_count | Nodes with zero edges | — |
orphan_ratio | orphan_count / total_nodes | < 0.2 (20%) |
provenance_coverage | Fraction of decisions with provenance edges | > 0.5 (50%) |
type_distribution | Count of nodes by memory type | — |
edge_distribution | Count of edges by edge type | — |
HealthReport
The HealthReport dataclass provides an is_healthy property that checks:
- Orphan ratio is below 20%
- Provenance coverage is above 50%
Usage
from smartmemory.metrics import GraphHealthChecker
checker = GraphHealthChecker(smart_memory)
report = checker.collect_health()
print(f"Healthy: {report.is_healthy}")
print(f"Orphan ratio: {report.orphan_ratio:.1%}")
print(f"Provenance coverage: {report.provenance_coverage:.1%}")REST API
| Method | Endpoint | Description |
|---|---|---|
| GET | /memory/graph/health | Collect health metrics |