Frame operations¶
Ordinary CognitionFrame transformations are immutable and lazy. Call collect(), collect_records(), to_records(), an export method, or pack() to execute the plan. In the 0.1 series, group_by().agg() evaluates its source immediately.
active = (
frame
.filter(cx.col("expires_at").is_null() | (cx.col("expires_at") > cx.now()))
.with_columns(priority=lambda row: row["priority"] + 1)
.sort("priority", descending=True)
.limit(100)
)
print(active.explain())
Operation summary¶
Operation |
0.1-series behavior |
|---|---|
|
Keeps rows for which an |
|
Projects columns; missing names become |
|
Adds or replaces values from constants, expressions, or callables |
|
Sorts one column with null values grouped by the Python planner |
|
Keeps the first non-negative number of rows |
|
Supports |
|
Supports |
|
Exact canonical |
|
Stores a score without changing row order |
|
Regex substitution for Text payloads only, with rehashing and lineage |
|
Changes matching rows to |
|
Explicitly changes retention; this is an application authorization decision |
Context frames and exploratory tables¶
collect() converts every row back to ContextItem and therefore requires id and payload. collect_records() returns ordinary dictionaries and can inspect projected or aggregated rows.
import cognoxium as cx
frame = cx.CognitionFrame.from_records([
{"id": "a", "payload": "one", "metadata": {"team": "x"}},
{"id": "b", "payload": "two", "metadata": {"team": "x"}},
]).with_columns(team=lambda row: row["metadata"]["team"])
summary = frame.group_by("team").agg(count=("count", "*"))
print(summary.collect_records())
[{'team': 'x', 'count': 2}]
Calling summary.collect() or summary.pack() raises SchemaError because an aggregate table is not model context.