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
| Rule | Pattern | Created Edge | Confidence |
|---|---|---|---|
| Causal Transitivity | A CAUSES B, B CAUSES C | A CAUSES C | 0.7 x (conf1 x conf2) |
| Contradiction Symmetry | A CONTRADICTS B | B CONTRADICTS A | 1.0 |
| Topic Inheritance | Decision DERIVED_FROM Semantic | Semantic INFLUENCES Decision | 0.6 |
How It Works
- Each rule has a pattern Cypher query that finds matching node pairs
- For each match, the engine creates a new edge with provenance metadata
- Metadata includes:
rule_name,confidence,inferred_at,inferred=true - 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
| Method | Endpoint | Description |
|---|---|---|
| POST | /memory/inference | Run inference engine |
| GET | /memory/inference/rules | List available rules |