Smritea

Search at one moment or over a range

Use valid_at to read memories as they stood at one moment, or from_time and to_time for a range.

Ask AI about this page

To read memories as they stood at one moment, pass valid_at to search. To read memories from a span of time, pass from_time, to_time or both. Every time must be an RFC 3339 time with a time zone.

These examples reuse client and a scope named alice, built as in Scope memories. The Go and Java examples take these values as parameters. The Go examples also take ctx.

Before you start

You need memories that carry dates. Smritea sets active_from and active_to when it stores a memory. Send event_occurred_at on add to give it a date. See Time-aware memory.

Search at one moment

  1. Pick the moment, for example 2026-01-15T00:00:00Z.
  2. Pass it as valid_at.
results = client.search(
    "Where does Alice live?",
    scope=alice,
    valid_at="2026-01-15T00:00:00Z",
)
for r in results:
    if r.memory:
        print(r.memory.active_from, r.memory.active_to, r.memory.content)

A memory matches when its active_from is on or before the moment, and its active_to is empty or on or after the moment. A memory with no active_from matches every moment.

Search a range

Pass from_time, to_time or both. A memory matches when its validity overlaps the range.

You passRange
from_time and to_timeFrom the first to the second, both inclusive.
from_time onlyFrom that moment onward.
to_time onlyUp to and including that moment.
results = client.search(
    "trips",
    scope=alice,
    from_time="2026-01-01T00:00:00Z",
    to_time="2026-03-31T23:59:59Z",
)

Handle the time errors

Search returns HTTP 400 with the code VALIDATION_FAILED when:

  • you send valid_at together with from_time or to_time, or
  • from_time is after to_time.

A time that is not valid RFC 3339 returns HTTP 400 with the code VALIDATION_ERROR instead.

from smritea import SmriteaBadRequestError

try:
    client.search(
        "trips",
        valid_at="2026-01-15T00:00:00Z",
        from_time="2026-01-01T00:00:00Z",
    )
except SmriteaBadRequestError as e:
    print(e.code, e)

Last updated on