ServicesEnrichments

Create an Enrichment

Define a derived value for each row of a Table, then refresh it to compute the values.

In development

Add a derived value, such as an is_left flag, to every row of frames without copying the Table or changing its schema. You define the Enrichment once as an expression over one row; creation stores only that definition, and a refresh computes the values.

Before you start

  • A Table in the Project, for example frames with a camera column.
  • Permission to create Resources in the Project.
  • A client for Python or Rust.
  • A Worker for the refresh Tasks.

Create the Enrichment

Create the Enrichment in a commit on the branch that holds the Table. The Enrichment is named under the Table, so is_left below becomes frames/is_left.

main = client.project("demo").branch("main")
frames = main.table("frames")
commit = main.commit()
commit.create_enrichment(frames, "is_left", eq(column("camera"), literal("left")))
commit.publish()

Creation checks the expression against the Table's schema and records the type of its value. It evaluates no rows: every row reads NULL until the first refresh.

Refresh the Enrichment

A refresh computes the values against the Table version at the commit it starts from. It runs as Tasks on Workers and publishes all the values in one commit, so readers see either the old values or the new ones. The first refresh computes every row; later ones compute only the rows whose inputs changed.

main = client.project("demo").branch("main")
task = main.enrichment("frames/is_left").refresh()
if task is None:
    print("a refresh of this Enrichment is already waiting")
else:
    print(f"published {len(task.wait().versions)} versions")

Refresh after writes to the Table, and after Table maintenance: maintenance moves rows, and the refresh copies their values into place without evaluating the expression again.

Verify the result

The refresh's result lists the Enrichment version it published. To check which Table version that version covers, see Inspect an Enrichment.

Troubleshooting

ProblemCause
The name is rejectedA stored column of the source Table has the same name.
The expression is rejectedThe expression filters, aggregates, joins, or generates rows, or reads a column the Table does not have. It must return one value for each row.
The refresh fails as supersededThe Enrichment changed after the commit the refresh started from, for example because another refresh published first. Refresh again from the current branch head.
The refresh reports an unsupported Enrichment versionThe Enrichment was created in Studio. Create it with the SDK instead.

Availability

Create and refresh Enrichments from Python and Rust. Reading the values beside a scan of frames is planned.

Found a problem? Edit this page or report an issue.

On this page