Temporal Knowledge Graph

The graph structure underlying Semantic Memory, enabling time-aware queries over subject-predicate-object triples.

Graph Structure


graph LR
  A[Alice] -->|prefers_language| B[Go]
  A -->|works_on| C[Project Alpha]
  C -->|has_deadline| D[2026-05-01]
  C -->|depends_on| E[Auth Service]
  E -->|maintained_by| F[Bob]

Temporal Dimensions

Every triple has temporal metadata:

  • valid_from: When the relationship became true
  • confidence: How certain we are about this fact
  • source: Which source this triple was added from

Query Patterns

The TripleStore.query() method supports filtering by subject, predicate, object, and point-in-time via as_of.

Direct Lookup

from mnemosyne.semantic import TripleStore

ts = TripleStore(db_path="mnemosyne.db")

# Who works on Project Alpha?
results = ts.query(predicate="works_on", object="Project Alpha")
# > Alice

Pattern Matching

# All relationships involving Alice
results = ts.query(subject="Alice")

# All reports_to relationships
results = ts.query(predicate="reports_to")

# Specific triple
results = ts.query(subject="Alice", predicate="prefers_language", object="Go")

Temporal Filtering

# What were Alice's preferences as of March 1?
results = ts.query(
  subject="Alice",
  predicate="prefers_language",
  as_of="2026-03-01",
)

The as_of parameter filters to only triples whose valid_from is on or before the given date.

Implementation

The graph is stored in SQLite with:

  • Triples table: Subject, predicate, object with temporal validity and confidence
  • Indices: Subject, predicate, object, and time-range indexes

No external graph database is required.

Note

The TripleStore does not currently support multi-hop graph traversal or graph statistics queries. Use query() with specific subject/predicate/object filters to retrieve relationships.