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:
| Field | Type | Description |
|---|---|---|
subject | TEXT | Entity (e.g., "Alice") |
predicate | TEXT | Relationship (e.g., "knows") |
object | TEXT | Target entity or value |
confidence | REAL | 0.0–1.0 fact confidence |
source | TEXT | Origin of this triple |
valid_from | TEXT/ISO date | When the fact became true |
Example Triples
| Subject | Predicate | Object | Confidence |
|---|---|---|---|
| Alice | prefers_language | Go | 0.95 |
| Project Alpha | has_deadline | 2026-05-01 | 0.90 |
| Bob | reports_to | Carol | 0.85 |
| API v2 | depends_on | Auth Service | 0.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.
Semantic Memory has no predefined ontology. Predicates are free-form strings. This allows dynamic knowledge domains without schema migrations.
Triple extraction from Working Memory during consolidation is not currently implemented. Triples must be added explicitly via add_triple() or TripleStore.add().
Mnemosyne