Parametric and External Knowledge › Worked Example: A Delayed Fact with Two Sources

Michael BrenndoerferDecember 1, 20269 min read
Language AI HandbookAll chapters
Part 45 of 67Knowledge, Memory, Editing, and Unlearning
Chapter 346Parametric and External Knowledge › Worked Example: A Delayed Fact with Two Sources
Reading section 7 of 10 · Worked Example: A Delayed Fact with Two Sources · 9 minSection 7 of 10 · 9 min

Section 7 of 10 · 9 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Assume this fictional company has one policy stream for the threshold and treats a signed policy memo as authoritative. The old memo sets $500. A signed revision sets $250 effective June 1, 2024, and reaches the index June 3. A team chat suggests $750. The chat is visible by June 2 but has no authority to set the threshold.

The resolver takes the date the policy must apply and the date that limits which records the service could have seen. It also needs the registry's required revision for the applicable date, using registry information available by that same cutoff. We supply this signal separately from the retrieved records. Without it, the resolver reports that it cannot verify freshness. In production, match the actual policy and revision identifiers. To replay a past answer, retain the registry signal and retrieval results the service had then.

We'll simulate the components, then implement a trust-aware resolver. The example checks an explicit policy and uses a structured value in the response. The notebook models decision logic locally and needs no model endpoint or search service.

Setup and dependencies

The resolver works on dates and immutable evidence records, using two standard-library imports.

PythonIn [4]
CollapseExpand
from dataclasses import dataclass
from datetime import date

The example uses structured threshold values in dollars. The fixture supplies signature status and the effective and indexing dates as trusted metadata. The resolver tests those fields. Document authentication and date validation belong upstream. The application can compare the values directly, so the example doesn't run a model to choose the threshold. A model used to word the answer would receive the resolved value and its citation, and the app could validate that the response preserved both.

PythonIn [5]
CollapseExpand
@dataclass(frozen=True)
class Evidence:
    source: str
    threshold: int
    effective_on: date
    indexed_on: date
    signed: bool

A signed memo can set the threshold. The chat record is available among the candidates but has no signing authority. A separate registry input specifies the required revision date.

PythonIn [6]
CollapseExpand
old = Evidence("memo-2022", 500, date(2022, 1, 15), date(2022, 1, 15), True)
current = Evidence("memo-2024", 250, date(2024, 6, 1), date(2024, 6, 3), True)
rumor = Evidence("team-chat", 750, date(2024, 5, 1), date(2024, 5, 1), False)
records = [old, current, rumor]

The old memo is still a real signed record in the fixture. The comparison needs to tell the difference between seeing an authoritative document and seeing the specific revision that governs the request.

A deterministic trust-aware resolver

Keep signed records whose effective date is at or before the applicable date and whose indexing date is at or before the observation cutoff. Then require a record from the registry's required revision date. If no signed records remain, report their absence. If signed records remain but lack the required revision, report the missing revision. Ask for a decision when two signed records for the required date give different thresholds. Among matching records that agree, select the first source ID in sorted order. For repeated copies with that ID, return the earliest indexed copy so retrieval order cannot change the returned record.

Each successful resolution carries one record for citation. Each other result carries a status and no evidence.

PythonIn [7]
CollapseExpand
@dataclass(frozen=True)
class Resolution:
    status: str
    evidence: Evidence | None = None

Now apply the filtering and conflict checks. A record effective by valid_on can still be unavailable if it was indexed after observed_on.

PythonIn [8]
CollapseExpand
def resolve_policy(
    items: list[Evidence],
    valid_on: date,
    observed_on: date,
    required_effective_on: date | None,
) -> Resolution:
    if required_effective_on is None or required_effective_on > valid_on:
        return Resolution("freshness unverified")

    signed = [
        item
        for item in items
        if item.signed
        and item.effective_on <= valid_on
        and item.indexed_on <= observed_on
    ]
    if not signed:
        return Resolution("no signed evidence")

    matching = [
        item for item in signed if item.effective_on == required_effective_on
    ]
    if not matching:
        return Resolution("required revision missing")

    if len({item.threshold for item in matching}) > 1:
        return Resolution("conflicting signed evidence")

    return Resolution(
        "resolved",
        min(matching, key=lambda item: (item.source, item.indexed_on)),
    )

The registry entry can be valid while the matching memo is absent from search. June 2 in this example exposes exactly that state. Returning the older memo as current would conceal the gap. The status instead lets the caller retry a trusted lookup or ask for human confirmation without supplying a threshold.

Building the context with explicit provenance

A response can carry a small set of fields computed from the resolved record. The example would pass those fields to a model only if the user interface needed it to phrase the answer. On failure, the response contains a status that the application can handle without inventing a citation.

PythonIn [9]
CollapseExpand
def response_record(resolution: Resolution) -> dict:
    evidence = resolution.evidence
    if evidence is None:
        return {"status": resolution.status}
    return {
        "status": resolution.status,
        "threshold_usd": evidence.threshold,
        "citation": evidence.source,
        "effective_on": evidence.effective_on.isoformat(),
    }

This keeps the source ID and the amount together through rendering. If a model presents the answer, compare its output with these fields before returning it. Both the resolver and the fields can be tested without a model.

Testing the resolution policy

The first three queries replay what the service could answer on each day, so both date arguments are the same. Then we ask from June 3 what policy applied on June 2. By that cutoff, the June 1 memo is available and can answer the retrospective question. The other cases cover unsigned evidence, an unavailable registry signal and disagreeing signed records.

PythonIn [10]
CollapseExpand
before = date(2024, 5, 31)
during = date(2024, 6, 2)
after = date(2024, 6, 3)
conflict = Evidence(
    "second-signed-memo", 300, current.effective_on, after, True
)
early_copy = Evidence(
    "early-indexed-copy", 250, current.effective_on, before, True
)
duplicate = Evidence("archive-copy", 250, current.effective_on, after, True)
repeated_id = Evidence(current.source, 250, current.effective_on, during, True)

scenarios = [
    ("May 31", resolve_policy(records, before, before, old.effective_on)),
    ("June 2", resolve_policy(records, during, during, current.effective_on)),
    ("June 3", resolve_policy(records, after, after, current.effective_on)),
    (
        "June 2 asked on June 3",
        resolve_policy(records, during, after, current.effective_on),
    ),
    ("Chat only", resolve_policy([rumor], after, after, current.effective_on)),
    ("Registry unavailable", resolve_policy(records, after, after, None)),
    (
        "Conflicting signed memos",
        resolve_policy(
            records + [conflict], after, after, current.effective_on
        ),
    ),
]

assert scenarios[0][1] == Resolution("resolved", old)
assert scenarios[1][1] == Resolution("required revision missing")
assert scenarios[2][1] == Resolution("resolved", current)
assert scenarios[3][1] == Resolution("resolved", current)
assert scenarios[4][1] == Resolution("no signed evidence")
assert scenarios[5][1] == Resolution("freshness unverified")
assert scenarios[6][1] == Resolution("conflicting signed evidence")

Next check empty input, early indexing and decisions that should remain stable across different retrieval orders. The response builder has two branches, one for a successful resolution and one for a withheld answer.

PythonIn [11]
CollapseExpand
assert resolve_policy([], after, after, current.effective_on) == Resolution(
    "no signed evidence"
)
assert resolve_policy(
    [early_copy, old], before, before, old.effective_on
) == Resolution("resolved", old)
assert resolve_policy(
    records, before, before, current.effective_on
) == Resolution("freshness unverified")
assert resolve_policy(
    records + [duplicate], after, after, current.effective_on
) == Resolution("resolved", duplicate)
assert resolve_policy(
    [duplicate] + records[::-1], after, after, current.effective_on
) == Resolution("resolved", duplicate)
assert resolve_policy(
    records + [repeated_id], after, after, current.effective_on
) == Resolution("resolved", repeated_id)
assert resolve_policy(
    [repeated_id] + records[::-1], after, after, current.effective_on
) == Resolution("resolved", repeated_id)

question = "What policy applied on June 2?"
later_answer = response_record(scenarios[3][1])
same_day_answer = response_record(scenarios[1][1])
assert later_answer["threshold_usd"] == current.threshold
assert later_answer["citation"] == current.source
assert later_answer["effective_on"] == "2024-06-01"
assert same_day_answer == {"status": "required revision missing"}
ConsoleOut [12]
CollapseExpand
What policy applied on June 2?
{'status': 'resolved', 'threshold_usd': 250, 'citation': 'memo-2024', 'effective_on': '2024-06-01'}
{'status': 'required revision missing'}

The retrospective response includes the threshold, its source and the effective date. The report for the same-day query includes only its status. Those are different responses to the same policy date because the observation cutoffs differ.

ConsoleOut [13]
CollapseExpand
May 31: $500 from memo-2022, effective 2022-01-15
June 2: required revision missing
June 3: $250 from memo-2024, effective 2024-06-01
June 2 asked on June 3: $250 from memo-2024, effective 2024-06-01
Chat only: no signed evidence
Registry unavailable: freshness unverified
Conflicting signed memos: conflicting signed evidence

On May 31, the system can cite the old memo. The same-day replay of June 2 reports a missing revision. From June 3, the system can cite the June 1 revision for both June 2 and June 3. A chat-only result, a missing registry signal and conflicting signed memos each return a different status without a dollar amount.

VisualizationOut [14]
CollapseExpand
Timeline with the registry requiring the new policy on June 1, a shaded two-day gap, and the signed memo becoming retrievable on June 3.
The June 1 revision governs starting on its effective date. In this fictional case it reaches the index on June 3. For same-day queries in this interval, search cannot supply the signed revision.

Effective time and availability answer different questions. On June 1 and June 2, the index does not yet contain the signed revision. A later question about what applied on those days can use the revision once it is indexed. If a source publishes its document before the rule takes effect, the order of the two events can reverse. The future-dated test exercises that case.

Why this example generalizes

A retrieval result has to be interpreted relative to its available records and the applicable policy. A missing registry signal means the system cannot verify freshness. A missing revision with a valid registry signal tells an operator which lookup to retry. A conflict among equally eligible signed values needs resolution by the policy owner or another authorized service.

The fixture collapses a policy and revision identity into a single date because it represents one policy stream. An application with several policy scopes should retain both IDs, the effective date and the observation boundary. An operator or support team can then reproduce the source decision by selecting the same scope and using the records observed for that request.

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy