Enterprise only
Overview
A column that a Geneva UDF filled can be handed over to a registered Function without computing its values again. TheALTER TABLE ... ALTER COLUMN ... AS statement binds a Function to an existing
column. It keeps the stored values and does not run the Function. After that,
a refresh computes only the rows that have no value yet, and the Function fills
new rows from then on.
The statement accepts only a plain column. It refuses a column that still
carries its Geneva UDF declaration, so the procedure has three steps:
- Replace the Geneva column with a plain copy of its values.
- Bind the plain column to the Function.
- Refresh the column to fill the rows that are still
NULL.
documents table with a text column, an embedding
column and a summary column. The Functions embed_text and summarize are
registered at version 1.
Prerequisites
- A registered Function for each column. See Create a Function. Its output type must match the column’s type exactly, including the vector dimension. Use the same model and parameters as the UDF that filled the column, so old and new rows are comparable.
- A table that does not have the Realtime Engine enabled. Steps 1 and 2 are refused on a table that has it.
- A window in which nothing writes to the table or changes its schema, for steps 1 and 2.
Geneva to Functions mapping
Procedure
Before you start, record which columns Geneva filled and how many rows each one has filled. You compare against these counts in Validation.Step 1: Replace the Geneva column with a plain copy
Stop writes to the table. Then copy each Geneva column, drop the original and rename the copy back. The copy runs on the deployment and reads the stored values. It does not call the UDF.IvfPq(distance_type="cosine").
The helper drops one column at a time. If one UDF fills several columns, copy
each of them first, drop them together in one drop_columns call, then rename
each copy.
Convert every Geneva column you plan to bind before you go to step 2. The
converted columns now come last in the schema, and each index keeps the name it
was built with, such as embedding_copy_idx.
Step 2: Bind the column to the Function
name => literal argument sets
one of the Function’s initialization values. version selects the Function
version. If you omit it, the latest published version is used and stays fixed
for the column.
Each statement returns one row, such as
Function column 'summary' declared on table 'documents'. The statement keeps
the stored values, the indexes and the column order. It does not run the
Function or rewrite data files. If the column was declared non-nullable, it
becomes nullable.
By running the statement, you declare that this Function version computed the
existing non-NULL values from the current inputs. LanceDB does not check
this.
Automatic refresh is enabled by default. Set auto_refresh_enabled = false so
that Function calls start only when you run a refresh.
The statement binds one top-level column and needs at least one input column.
It is refused, and the table stays unchanged, for:
- a column whose type does not match the Function’s output type
- a column that is already computed, or still carries a Geneva UDF declaration
- a primary key column
- a column that another Function binding reads or writes
- a Function whose result is expanded into several columns
- a materialized view
- a table that has the Realtime Engine enabled
Step 3: Refresh the column
NULL. It leaves the
other rows alone while their inputs are unchanged. If Geneva filled every row,
the refresh assigns no rows.
Add a filter to keep rows out of the refresh, such as rows with empty input. A
filtered refresh recomputes every matching row, including rows that already
have a value. Add AND <column> IS NULL to the filter so that only unfilled
rows are computed:
error_policy="skip", rows that succeed are kept when other rows fail.
See row errors.
Rows you add later have no value in the column. Run the same refresh after
each load, or turn on automatic refresh:
Behavior differences
NULLmeans not filled. A Function with a non-nullable output cannot returnNULL. Use a refresh filter to leave rows unfilled. See Function signatures.- A
NULLinput defers the row. When the Function’s parameter is declared non-nullable, a row with aNULLinput is not computed and its output staysNULL. - A bound column cannot be written directly. Its values come from refresh. Leave the column out of the rows you append.
- A changed Function is a new version. A bound column stays on the version it was bound with.
- Arguments are fixed at binding. To change a literal or an initialization value, drop the column and add it again with the new value. The new column starts empty.
- Overwriting the table is refused while it has Function columns. Append
rows or use
merge_insert. - Refresh filters accept less SQL than queries. Comparisons,
IS NULL,AND,IN,LIKEand built-in functions such aslowerwork. TheTRIM(...)syntax is rejected, so usebtrim(...). Registered Functions and non-deterministic functions such asnow()are also rejected. - A
retry_policychanges how a failed call is handled. A whole call that still fails after its retries is not split up to find the failing row. See retrying temporary Function errors.
Validation
- Run the procedure on a copy of the table first.
- After step 2, print the schema and the filled counts again. The counts match
the ones you recorded, no column is marked as a Geneva column, and
table.list_indices()lists each index. - After step 3, check that
rows_failedis0and thattable.function_errors(column="embedding")has no records. - Run
SHOW COLUMN STATUS ON documentsto see the Function, the version and the row counts of each bound column. The statement returns an error while it cannot account for every unfilled row. That is the case right after step 2 if the column hasNULLrows. See checking column status. - Compare a sample of newly computed rows with rows the UDF computed. For an embedding, check the dimension and run the same search against both.
- Run one load of new rows end to end before you turn the Geneva job off.