SmartMemory
Concepts

Inference Engine

SmartMemory automatically enriches the knowledge graph by applying inference rules that create new edges from existing patterns — similar to OWL-RL deductive closure.

Built-in Rules

RulePatternCreated EdgeConfidence
Causal TransitivityA CAUSES B, B CAUSES CA CAUSES C0.7 x (conf1 x conf2)
Contradiction SymmetryA CONTRADICTS BB CONTRADICTS A1.0
Topic InheritanceDecision DERIVED_FROM SemanticSemantic INFLUENCES Decision0.6

How It Works

  1. Each rule has a pattern Cypher query that finds matching node pairs
  2. For each match, the engine creates a new edge with provenance metadata
  3. Metadata includes: rule_name, confidence, inferred_at, inferred=true
  4. Confidence is computed per-rule (e.g., transitive chains multiply confidence)

Usage

from smartmemory.inference import InferenceEngine

engine = InferenceEngine(smart_memory)

# Preview what would be created
result = engine.run(dry_run=True)
print(f"Would create {result.edges_created} edges")

# Apply for real
result = engine.run(dry_run=False)
print(f"Created {result.edges_created} inferred edges")

Custom Rules

from smartmemory.inference import InferenceRule

custom_rule = InferenceRule(
    name="topic_similarity",
    description="Link items sharing the same topic",
    pattern_cypher="MATCH (a)-[:HAS_TOPIC]->(t)<-[:HAS_TOPIC]-(b) WHERE a <> b RETURN a, b",
    edge_type="SIMILAR_TOPIC",
    confidence=0.5,
)

engine = InferenceEngine(smart_memory, rules=[custom_rule])

REST API

MethodEndpointDescription
POST/memory/inferenceRun inference engine
GET/memory/inference/rulesList available rules

On this page