Concepts
Graph Validation
SmartMemory validates memory items and edges at runtime against schema constraints, catching data quality issues before they propagate through the knowledge graph.
Why Validation Matters
Without validation:
- Malformed memories enter the graph silently
- Invalid edges connect unrelated node types
- Orphaned nodes accumulate over time
- Provenance gaps make reasoning unreliable
Components
MemoryValidator
Validates individual memory items against schema rules:
| Check | Severity | Description |
|---|---|---|
| Empty content | Error | Items must have non-empty content |
| Unknown memory type | Warning | Type not in registered MEMORY_TYPES set |
| Confidence range | Error | Must be between 0.0 and 1.0 |
| Decision fields | Warning | Decision items should have decision_id |
| Reasoning fields | Warning | Reasoning items should have trace_id |
EdgeValidator
Validates edges against registered EdgeSchema definitions:
| Check | Severity | Description |
|---|---|---|
| Unknown edge type | Warning | Edge type not in schema registry |
| Invalid source type | Error | Source node type not allowed by schema |
| Invalid target type | Error | Target node type not allowed by schema |
Also provides:
- Orphan detection: Find nodes with zero edges
- Provenance gap detection: Find nodes missing DERIVED_FROM, CAUSED_BY, or PRODUCED edges
Usage
from smartmemory.validation import MemoryValidator, EdgeValidator
validator = MemoryValidator(smart_memory)
result = validator.validate_item(item)
if not result.is_valid:
for error in result.errors:
print(f"ERROR: {error.field} - {error.message}")
edge_validator = EdgeValidator(smart_memory)
orphans = edge_validator.find_orphan_nodes()REST API
| Method | Endpoint | Description |
|---|---|---|
| POST | /memory/validate | Validate a specific item |
| GET | /memory/graph/health | Get graph health metrics |