> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate from Geneva

> Move columns that Geneva UDFs filled to registered Functions, and keep the values already computed.

Enterprise only

## Overview

A column that a [Geneva](https://docs.lancedb.com/oss/v0-42-0/geneva.md) UDF filled can be handed over to a registered
[Function](https://docs.lancedb.com/oss/v0-42-0/management/function.md) without computing its values again. The
`ALTER 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:

1. Replace the Geneva column with a plain copy of its values.
2. Bind the plain column to the Function.
3. Refresh the column to fill the rows that are still `NULL`.

The examples use a `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](https://docs.lancedb.com/oss/v0-42-0/curation/create-function.md). 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](https://docs.lancedb.com/oss/v0-42-0/tables/realtime-engine.md)
  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

| Geneva | Functions |
| - | - |
| `@udf` from `geneva` | `@function` from `lancedb` |
| The UDF is serialized and attached to the column | The Function is registered once with `db.create_function_async`, versioned, then bound to columns |
| `table.add_columns({...})`, then `table.backfill(col)` | `table.add_columns({...}, auto_refresh_enabled=False)`, then `table.refresh_column_async(col)` |
| `concurrency` on the backfill: the number of worker processes | `total_cpu_millis`, `total_memory_bytes`, and `total_gpu_count` on the refresh: a CPU and memory ceiling for the whole job. LanceDB sets the worker count within it |
| `intra_applier_concurrency` on the backfill: threads in each worker process | No setting. Run concurrent work inside the Function's own code, such as a thread pool |
| `@udf(on_error=[Retry(...)])` | Retries in the Function's own client code, or a [`retry_policy`](https://docs.lancedb.com/oss/v0-42-0/sql/dml/refresh#function-retries) |
| API key read from the client environment and serialized with the UDF | A [Secret](https://docs.lancedb.com/oss/v0-42-0/management/secret.md) created with `db.create_secret(...)` and bound to the Function with `EnvVarSecret` |
| Row errors from `table.get_errors(...)` | `table.function_errors(column=...)`, one record per failed row |

## Procedure

Before you start, record which columns Geneva filled and how many rows each
one has filled. You compare against these counts in [Validation](#validation).

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
for field in table.schema:
    geneva = any(key.decode().startswith("virtual_column") for key in (field.metadata or {}))
    print(field.name, field.type, "Geneva column" if geneva else "")

for column in ("embedding", "summary"):
    print(column, table.count_rows(f"{column} IS NOT NULL"))
```

### 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.

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
from lancedb.index import IvfPq


def to_plain(table, column, index=None):
    copy = f"{column}_copy"
    table.add_columns({copy: column})
    if index is not None:
        table.create_index_async(copy, config=index, replace=True).wait()
    table.drop_columns([column])
    table.alter_columns({"path": copy, "rename": column})


to_plain(table, "embedding", index=IvfPq(distance_type="cosine"))
to_plain(table, "summary")
```

Dropping the original column also removes its index, so build the index on the
copy first. Use your own index settings in place of
`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

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
db.execute_query("""
    ALTER TABLE documents ALTER COLUMN embedding AS embed_text(text)
    WITH (version = '1', auto_refresh_enabled = false)
""").read_all()

db.execute_query("""
    ALTER TABLE documents ALTER COLUMN summary
    AS summarize(text, prompt => 'Summarize this text in two sentences')
    WITH (version = '1', auto_refresh_enabled = false)
""").read_all()
```

Positional arguments name the input columns. A `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](https://docs.lancedb.com/oss/v0-42-0/tables/realtime-engine.md) enabled

Writes that started before the statement are not blocked. One of them can
still overwrite the column after it is bound. Resume writes only after the
statement returns and your clients have reopened the table.

### Step 3: Refresh the column

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
job = table.refresh_column_async("embedding")
result = job.wait()
print(result.rows_assigned, result.rows_failed)
```

A refresh without a filter fills the rows whose value is `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:

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
job = table.refresh_column_async(
    "summary",
    where="text != '' AND summary IS NULL",
    error_policy="skip",
)
```

With `error_policy="skip"`, rows that succeed are kept when other rows fail.
See [row errors](https://docs.lancedb.com/oss/v0-42-0/sql/dml/refresh.md#row-errors).

Rows you add later have no value in the column. Run the same refresh after
each load, or turn on [automatic refresh](https://docs.lancedb.com/oss/v0-42-0/enterprise/auto-refresh.md):

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
ALTER TABLE documents ALTER COLUMN embedding SET auto_refresh_enabled = true;
```

Automatic refresh runs without a filter, so it also computes rows that your
filter kept out.

## Behavior differences

* **`NULL` means not filled.** A Function with a non-nullable output cannot
  return `NULL`. Use a refresh filter to leave rows unfilled. See
  [Function signatures](https://docs.lancedb.com/oss/v0-42-0/curation/create-function.md#signature-types).
* **A `NULL` input defers the row.** When the Function's parameter is declared
  non-nullable, a row with a `NULL` input is not computed and its output stays
  `NULL`.
* **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`, `LIKE` and built-in functions such as `lower` work. The
  `TRIM(...)` syntax is rejected, so use `btrim(...)`. Registered Functions
  and non-deterministic functions such as `now()` are also rejected.
* **A `retry_policy` changes 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](https://docs.lancedb.com/oss/v0-42-0/sql/dml/refresh.md#function-retries).

## Validation

1. Run the procedure on a copy of the table first.
2. 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.
3. After step 3, check that `rows_failed` is `0` and that
   `table.function_errors(column="embedding")` has no records.
4. Run `SHOW COLUMN STATUS ON documents` to 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 has `NULL` rows. See
   [checking column status](https://docs.lancedb.com/oss/v0-42-0/sql/dml/refresh.md#show-column-status).
5. 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.
6. Run one load of new rows end to end before you turn the Geneva job off.

## Related guidance

* [Create a computed column](https://docs.lancedb.com/oss/v0-42-0/feature-engineering/add-computed-column.md)
* [Refresh a computed column](https://docs.lancedb.com/oss/v0-42-0/feature-engineering/refresh-column.md)
* [Handle Function failures](https://docs.lancedb.com/oss/v0-42-0/management/function-failures.md)
* [Operate Function workloads](https://docs.lancedb.com/oss/v0-42-0/enterprise/function-operations.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.