SmartMemory
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:

CheckSeverityDescription
Empty contentErrorItems must have non-empty content
Unknown memory typeWarningType not in registered MEMORY_TYPES set
Confidence rangeErrorMust be between 0.0 and 1.0
Decision fieldsWarningDecision items should have decision_id
Reasoning fieldsWarningReasoning items should have trace_id

EdgeValidator

Validates edges against registered EdgeSchema definitions:

CheckSeverityDescription
Unknown edge typeWarningEdge type not in schema registry
Invalid source typeErrorSource node type not allowed by schema
Invalid target typeErrorTarget 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

MethodEndpointDescription
POST/memory/validateValidate a specific item
GET/memory/graph/healthGet graph health metrics

On this page