Semantic Memory

Structured knowledge storage using a temporal knowledge graph. Stores facts, relationships, and concepts as subject-predicate-object triples with temporal validity.

TripleStore Class

Semantic Memory is managed by the TripleStore class, which is separate from the main Memory class. It is not accessed via mem.add_fact() or mem.query_facts().

Module-Level Functions

from mnemosyne.semantic import add_triple, query_triples

# Add a triple
add_triple(
  subject="Project Alpha",
  predicate="has_deadline",
  object="2026-05-01",
  confidence=0.90,
  source="user",
  valid_from="2026-04-25",
)

# Query triples
results = query_triples(
  subject="Project Alpha",
  predicate="has_deadline",
)

TripleStore Instance

from mnemosyne.semantic import TripleStore

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

# Add a triple
ts.add(
  subject="Alice",
  predicate="prefers_language",
  object="Go",
  confidence=0.95,
  source="user",
  valid_from="2026-04-20",
)

# Query triples
results = ts.query(
  subject="Alice",
  predicate="prefers_language",
)

# Temporal query — what was true as of a specific date?
results = ts.query(
  subject="Alice",
  predicate="prefers_language",
  as_of="2026-03-01",
)

Triple Schema

Each triple has the following fields:

FieldTypeDescription
subjectTEXTEntity (e.g., "Alice")
predicateTEXTRelationship (e.g., "knows")
objectTEXTTarget entity or value
confidenceREAL0.0–1.0 fact confidence
sourceTEXTOrigin of this triple
valid_fromTEXT/ISO dateWhen the fact became true

Example Triples

SubjectPredicateObjectConfidence
Aliceprefers_languageGo0.95
Project Alphahas_deadline2026-05-010.90
Bobreports_toCarol0.85
API v2depends_onAuth Service0.80

Temporal Validity

The as_of parameter in query() enables point-in-time queries. Only triples whose valid_from is on or before the specified date are returned. This lets you ask "what did we know at time X?"

# What did we know about Project Alpha's deadline on April 1?
results = ts.query(
  subject="Project Alpha",
  predicate="has_deadline",
  as_of="2026-04-01",
)

Storage

The TripleStore is backed by SQLite. No external graph database is required.

Schema Flexibility

Semantic Memory has no predefined ontology. Predicates are free-form strings. This allows dynamic knowledge domains without schema migrations.

No Auto-Extraction

Triple extraction from Working Memory during consolidation is not currently implemented. Triples must be added explicitly via add_triple() or TripleStore.add().