Knowledge Freshness and Temporal Updates › Bi-Temporal Facts: Valid Time vs. Ingestion Time
Language AI HandbookAll chapters The foundational primitive is the bi-temporal record. A single fact carries two independent time axes:
- Valid time is the period when an assertion applies in the world being modeled. Acme's current records put Bob's start date at February 1, 2023.
- Transaction time, or system time, is the period when the database recorded that version of the assertion. In this toy it begins when the update is committed to the store.
Why both? Because "what was true in the world" and "what your system knew" diverge constantly:
- A late-arriving document corrects a fact about 2019. Valid time is 2019; ingestion time is today.
- A document can announce an appointment months before it takes effect. Publication precedes the appointment's valid start, while ingestion can occur on either side of the start.
- A retraction can end the period when the database asserted a claim, even if later evidence shows that the claim never held.
A current historical query uses date X for valid time and the latest committed state for transaction time. To reconstruct what the store believed about date X last Tuesday, keep the same valid date and set the transaction cutoff to last Tuesday.
A bitemporal record has a validity interval and a transaction interval . Subscripts and mark the start and end. An open transaction end identifies a version still asserted by the store. A revision closes earlier transaction intervals and appends a new timeline while preserving the earlier assertions.
Ending an older row's transaction interval preserves its payload for historical queries. An in-place replacement of the payload would need a separate history or log to recover what the system believed earlier.
An entity ID determines which rows a revision may replace. A retriever can produce candidates for several companies named Acme, so resolve the intended entity before applying a CEO timeline. Preserve the source ID separately from the entity ID. That lets an auditor distinguish two sources asserting different dates about the same company from two unrelated companies sharing a name. This example treats CEO as a single-valued attribute. A joint role or a concurrent association needs a different representation and should not use the nonoverlap rule below.
Representing the intervals
We can represent a fact as a small dataclass with four timestamps plus the payload. Let us set up the machinery now and use it throughout the chapter.
PythonIn [3]Expand
from dataclasses import dataclass, field
from datetime import datetime, timedelta, timezone
from typing import Optional
def utc(*args) -> datetime:
"""Convenience: build a timezone-aware UTC datetime."""
return datetime(*args, tzinfo=timezone.utc)
@dataclass
class Fact:
subject: str
predicate: str
obj: str
# Valid time: when the fact is true in the world.
valid_start: datetime
valid_end: Optional[datetime] = None # None = still true
# Transaction time: when our system believed it.
trans_start: datetime = field(
default_factory=lambda: datetime.now(timezone.utc)
)
trans_end: Optional[datetime] = None # None = currently believed
source: str = ""
def believed_at(self, t: datetime) -> bool:
"""Was this record the system's belief at transaction time t?"""
return self.trans_start <= t and (
self.trans_end is None or t < self.trans_end
)
def valid_at(self, t: datetime) -> bool:
"""Was the fact true in the world at valid time t?"""
return self.valid_start <= t and (
self.valid_end is None or t < self.valid_end
)The two predicates believed_at and valid_at are the heart of the model. Note the half-open interval convention [start, end): a fact whose valid_end is exactly t is not valid at t, which avoids ambiguity at boundaries. Consistency matters more than the choice; pick half-open and never mix.
For a single-valued attribute like CEO, the toy replaces the complete believed timeline for one key at a time. The key uses a stable entity ID and predicate. Two companies with the same display name need different entity IDs. All fixture dates are UTC and updates run in one process.
PythonIn [4]Expand
class TemporalKnowledgeBase:
def __init__(self):
self.records: list[Fact] = []
self.last_revision: dict[tuple[str, str], datetime] = {}
def revise_timeline(self, subject, predicate, intervals, *, at):
key = (subject, predicate)
if key in self.last_revision and at <= self.last_revision[key]:
raise ValueError("Transaction times must increase per key")
intervals = sorted(intervals, key=lambda interval: interval[1])
replacement = []
for i, (obj, start, end, source) in enumerate(intervals):
if end is not None and end <= start:
raise ValueError("Validity intervals must have positive length")
if i:
previous_end = intervals[i - 1][2]
if previous_end is None or previous_end > start:
raise ValueError("Validity intervals must not overlap")
replacement.append(
Fact(subject, predicate, obj, start, end, at, source=source)
)
for row in self.records:
if (row.subject, row.predicate) == key and row.trans_end is None:
row.trans_end = at
self.records.extend(replacement)
self.last_revision[key] = at
def as_of_belief(self, t: datetime):
return [row for row in self.records if row.believed_at(t)]
def as_of_world(self, t: datetime, *, known_at: Optional[datetime] = None):
rows = (
self.as_of_belief(known_at)
if known_at is not None
else [row for row in self.records if row.trans_end is None]
)
return [row for row in rows if row.valid_at(t)]The store validates the replacement timeline before closing any rows. This lets the new timeline preserve Alice's earlier tenure while adding Bob. A belief query selects the rows recorded at a transaction time. A world query filters that state by valid time. When the caller omits known_at, the world query uses the latest committed state. A valid date in a gap returns no assertion for that key.
A worked example
Let's make the divergence concrete. We track the CEO of a fictional company across a real-world change and a late-arriving correction.
PythonIn [5]Expand
ACME = "acme-industries-us"
kb = TemporalKnowledgeBase()
alice_start = utc(2014, 1, 1)
initial_bob_start = utc(2023, 3, 1)
corrected_bob_start = utc(2023, 2, 1)
kb.revise_timeline(
ACME,
"CEO",
[("Alice", alice_start, None, "initial-filing")],
at=utc(2024, 1, 1),
)
kb.revise_timeline(
ACME,
"CEO",
[
("Alice", alice_start, initial_bob_start, "appointment-filing"),
("Bob", initial_bob_start, None, "appointment-filing"),
],
at=utc(2024, 6, 15),
)
kb.revise_timeline(
ACME,
"CEO",
[
("Alice", alice_start, corrected_bob_start, "corrected-filing"),
("Bob", corrected_bob_start, None, "corrected-filing"),
],
at=utc(2024, 9, 1),
)ConsoleOut [6]Expand
Alice valid [2014-01-01, open) recorded [2024-01-01, 2024-06-15) Alice valid [2014-01-01, 2023-03-01) recorded [2024-06-15, 2024-09-01) Bob valid [2023-03-01, open) recorded [2024-06-15, 2024-09-01) Alice valid [2014-01-01, 2023-02-01) recorded [2024-09-01, open) Bob valid [2023-02-01, open) recorded [2024-09-01, open) May 1 as known on May 1: ['Alice'] May 1 using the corrected history: ['Bob']
Five rows represent three revisions. In May the store still recorded Alice's open interval. In the latest record, Bob covers the same valid date and Alice remains the recorded CEO for dates before February 1, 2023.
The two answers address different requests. One reconstructs the record available in May. The other uses the latest evidence to answer a historical question.
The plot pairs each row's valid and transaction intervals on a shared axis. Open ends extend to the display horizon.
PythonIn [7]Expand
import matplotlib.dates as mdates
# Materialize the interval spans for plotting. "Open" ends are drawn to a
# fixed horizon so the bars have a right edge.
plot_horizon = utc(2025, 1, 1)
record_rows = []
for i, r in enumerate(kb.records):
v_end = r.valid_end or plot_horizon
t_end = r.trans_end or plot_horizon
record_rows.append(
{
"idx": i,
"label": f"{r.obj}, recorded {r.trans_start.date()}",
"valid_start": mdates.date2num(r.valid_start),
"valid_end": mdates.date2num(v_end),
"trans_start": mdates.date2num(r.trans_start),
"trans_end": mdates.date2num(t_end),
}
)
n_records = len(record_rows)VisualizationOut [8]Expand

The top row is the original Alice assertion. The next two rows show the June timeline, followed by the September revision. Compare Alice's two end dates and Bob's two start dates. The backdating changes the valid boundary while the revision is still recorded in September.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!