Files
lancedb/docs/web/curation/vend-secret.mdx
T
Brendan Clement 27b7a248e4 docs: use refresh_column_async with wait on Enterprise pages (#5183)
## The problem

Several Python examples on Enterprise pages start a computed column
refresh with `table.refresh_column(...)`. On a LanceDB Enterprise
connection that call always fails:

```
NotImplementedError: not supported: a remote refresh runs as a server job; use refresh_column_async and wait on the returned handle
```

On Enterprise a refresh runs as a job on the server. Only
`refresh_column_async(...)` works there: it returns a job, and
`job.wait()` blocks until the job finishes. A reader following the
quickstart's Enterprise step, or the secrets or GPU examples, hits the
error. The same fix landed for the Sophon-owned page in
lancedb/sophon#10478.

## What this changes

- **The examples use the job form:** `job =
table.refresh_column_async(...)` then `job.wait()`. This covers
`curation/vend-secret.mdx`, `curation/create-function.mdx` and the
quickstart, plus the sentences that named the blocking call in
`enterprise/auto-refresh.mdx` and
`feature-engineering/add-computed-column.mdx`.
- **The quickstart example now comes from a test.** The
`PyQuickstartAddFeature` snippet is generated from the deployment test
in `docs/web-tests/py/test_quickstart.py`, and the separate
Enterprise-only snippet is folded into it. That test also asserts that
the blocking call raises an error naming `refresh_column_async`.
- **The GPU example only shows arguments the Enterprise table accepts
today.** `gpu_class` and `gpu_count` are dropped from `add_columns`, and
`gpu_count` from the refresh call, with a one-sentence note. See "Python
wrapper gap" below.

## How it was checked

Every Enterprise call the changed pages show was run through the Python
SDK (0.42.0b26, built from this branch) against a local stand-in for an
Enterprise server that returns canned responses:

- `table.refresh_column("embedding")` raises the error above and sends
no request.
- `job = table.refresh_column_async("embedding"); job.wait()` submits a
refresh job and returns its result.
- `table.refresh_column_async("embedding", gpu_class="h100",
total_gpu_count=8).wait()` is accepted, and the server receives both GPU
options.
- The removed forms fail as expected: `gpu_count` on
`refresh_column_async`, and `gpu_class` or `gpu_count` on `add_columns`,
raise `TypeError: unexpected keyword argument`.

Also: the committed quickstart snippet matches what the generator
produces from the test, and the five changed pages render with no
blocking call in a local preview.

**Not run:** the quickstart deployment test itself. It needs a real
Enterprise deployment and is skipped without credentials, which CI does
not have. Registering a Function also needs a real deployment, so that
line of the GPU example was not exercised.

## Python wrapper gap (to be fixed separately)

The Python `RemoteTable.refresh_column_async` and
`RemoteTable.add_columns` do not accept `gpu_count`, and `add_columns`
also does not accept `gpu_class`. The Rust remote table supports these
GPU placement options, so this looks like an oversight in the Python
layer. This PR makes no SDK change. Once the wrapper passes them
through, the GPU example can show them again.

## Risk

Low. Docs and docs tests only.

## Pipeline

Updates from [git push
no-mistakes](https://github.com/kunchenguid/no-mistakes)

<!-- no-mistakes-pipeline-attestation:v1
{"head_sha":"11ac1a260e8825dd406dea4e839f2498309e843b","steps":[{"step":"intent","status":"completed"},{"step":"rebase","status":"completed"},{"step":"review","status":"completed"},{"step":"test","status":"completed"},{"step":"document","status":"completed"},{"step":"lint","status":"completed"},{"step":"push","status":"completed"},{"step":"pr","status":"running"},{"step":"ci","status":"pending"}],"live_validation":{"verdict":"go","live":7,"total":9}}
-->

<details>
<summary>✅ **Intent** - passed</summary>

✅ No issues found.
</details>

<details>
<summary>✅ **Rebase** - passed</summary>

✅ No issues found.
</details>

<details>
<summary>✅ **Review** - passed</summary>

✅ No issues found.
</details>

<details>
<summary>⚠️ **Test** - 2 infos</summary>

- ⚠️ `docs/web/curation/create-function.mdx:546` - Not confirmed live.
The new example calls `table.refresh_column_async(&#34;embedding&#34;,
gpu_class=&#34;h100&#34;, gpu_count=4, total_gpu_count=8)`, but
`RemoteTable.refresh_column_async` in
python/python/lancedb/remote/table.py (line 1280) has no `gpu_count`
parameter (only `gpu_class` and `total_gpu_count`), while the abstract
`Table` and `LanceTable` do. If that reading holds, the documented call
raises `TypeError: unexpected keyword argument &#39;gpu_count&#39;` on
Enterprise. The blocking `RemoteTable.refresh_column` has the same gap,
so this predates the change, but the page still shows a call that may
not run. Decision needed: drop `gpu_count=4` from the example, or add
the parameter to the Enterprise table (an SDK change beyond this docs
change).
- ⚠️ The intent asked whether the docs change can be validated by
running code. In this run it could not: the SDK build did not finish in
the time budget and no Enterprise deployment credentials are available,
so the only test covering the changed quickstart snippet
(`test_quickstart_derived_feature_on_a_deployment`) skips. The prepared
driver script in the evidence directory exercises the three documented
calls against a localhost emulator once the SDK is built.
- ⚠️ live validation verdict: inconclusive (4 of 7 scenarios were driven
live against the product); untested: On an Enterprise connection
(localhost emulator, synthetic responses) the documented `job =
table.refresh_column_async(&#34;embedding&#34;); job.wait()` completes,
and the old blocking `table.refresh_column(...)` raises
NotImplementedError naming refresh_column_async, On an Enterprise
connection the create-function.mdx example
`table.refresh_column_async(&#34;embedding&#34;,
gpu_class=&#34;h100&#34;, gpu_count=4, total_gpu_count=8)` is accepted
and submits a job, `test_quickstart_derived_feature_on_a_deployment`
passes against a real LanceDB Enterprise deployment
- Live validation: ⚠️ inconclusive - 4 of 7 scenarios driven live
against the product

| Scenario | Result | Live | Evidence |
| --- | --- | --- | --- |
| Reader opens the six changed docs pages in the local Mintlify preview
and sees the job form (`refresh_column_async` + `job.wait()`) with no
blocking `table.refresh_column(` call left | ✅ pass | live |
Rendered-page check output (artifact &#39;Rendered docs check&#39;) and
saved HTML under
~/.no-mistakes/evidence/01M85TWQ599ZJ5NQ0DBASSFT91/rendered |
| Reader follows the new `refresh_column_async` link on the
computed-column page and lands on the &#39;Run a refresh on
Enterprise&#39; section | ✅ pass | live | Rendered add-computed-column
page links to /feature-engineering/refresh-column#async; the rendered
refresh-column page (HTTP 200) contains an element with
id=&#34;async&#34; |
| Quickstart page still renders after the Enterprise-only snippet import
was removed, and its feature step shows the job form | ✅ pass | live |
quickstart returns HTTP 200; page payload contains `job =
table.refresh_column_async(&#34;quality_score&#34;)\njob.wait()`; no
`PyQuickstartAddFeatureEnterprise` reference remains |
| Regenerating snippets from docs/web-tests/py/test_quickstart.py
reproduces the committed `PyQuickstartAddFeature` snippet | ✅ pass |
live | `mdx_snippets_gen.py` output in
~/.no-mistakes/evidence/01M85TWQ599ZJ5NQ0DBASSFT91/snippets-regen/quickstart.mdx
is identical to docs/web/snippets/quickstart.mdx for that export |
| On an Enterprise connection (localhost emulator, synthetic responses)
the documented `job = table.refresh_column_async(&#34;embedding&#34;);
job.wait()` completes, and the old blocking `table.refresh_column(.… |
⏸️ untested | no | Needs the Python SDK built from this worktree. `uv
run ... maturin develop` started from a cold cargo cache and was still
compiling after about 18 minutes, so I stopped it to stay inside the
30-minute… |
| On an Enterprise connection the create-function.mdx example
`table.refresh_column_async(&#34;embedding&#34;,
gpu_class=&#34;h100&#34;, gpu_count=4, total_gpu_count=8)` is accepted
and submits a job | ⏸️ untested | no | Blocked by the same unfinished
SDK build. The source suggests this call would raise TypeError (see
finding), but that was not executed. |
| `test_quickstart_derived_feature_on_a_deployment` passes against a
real LanceDB Enterprise deployment | ⏸️ untested | no | The test skips
unless LANCEDB_DOCS_TEST_DEPLOYMENT=1 and LANCEDB_URI,
LANCEDB_HOST_OVERRIDE and LANCEDB_API_KEY point at a deployment with a
Function catalog; a localhost emulator cannot stand in for… |

- <code>`cd docs/web &amp;&amp; mint dev --port 3391 --no-open`, then
`curl http://localhost:3391/&lt;page&gt;` for quickstart,
curation/vend-secret, curation/create-function, enterprise/auto-refresh,
feature-engineering/add-computed-column,
feature-engineering/refresh-column (all HTTP 200), with a text check of
each rendered page</code>
- <code>`python3 docs/web-tests/mdx_snippets_gen.py -s docs/web-tests/py
-s docs/web-tests/ts -s docs/web-tests/rs -o
&lt;evidence&gt;/snippets-regen`, then diff of `PyQuickstartAddFeature`
against `docs/web/snippets/quickstart.mdx`</code>
- <code>`cd python &amp;&amp; uv run --extra tests --extra dev maturin
develop --extras tests,dev` (started, not finished within budget,
stopped; no result)</code>
- <code>`chrome-devtools-axi` screenshots of the rendered pages (failed:
BRIDGE_NOT_READY)</code>
- <code>Source read of `python/python/lancedb/remote/table.py`
`refresh_column_async` signature against the create-function.mdx example
(not live)</code>

🔧 Fix applied.
2 infos still open:

- ℹ️ No screenshots of the rendered docs pages were captured.
`chrome-devtools-axi` failed with &#34;Bridge failed to start within
30s&#34; and headless Google Chrome hung until killed at 60s per page.
The pages were instead fetched as served HTML from a local `mint dev`
preview and saved under rendered-round2/. For the quickstart page the
job-form snippet is present only in the page&#39;s hydration payload,
not as rendered text, so its on-screen appearance was not seen.
- ℹ️ `docs/web-tests/py/test_quickstart.py:347` -
`test_quickstart_derived_feature_on_a_deployment`, the only test that
runs the changed quickstart snippet end to end, skips because no
Enterprise deployment credentials exist (LANCEDB_DOCS_TEST_DEPLOYMENT,
LANCEDB_URI, LANCEDB_HOST_OVERRIDE, LANCEDB_API_KEY). The same calls
were driven against a localhost emulator instead, which does not prove
real-deployment behaviour.
- Live validation: ✅ go - 7 of 9 scenarios driven live against the
product

| Scenario | Result | Live | Evidence |
| --- | --- | --- | --- |
| On an Enterprise connection (Python SDK, localhost emulator, synthetic
responses) the documented `job =
table.refresh_column_async(&#34;embedding&#34;); job.wait()` submits a
refresh job and returns its resul… | ✅ pass | live |
driver-output-round2.txt: OK -&gt; rows_assigned=3 ...; server received
POST /v1/table/test/backfill_column {&#39;column&#39;:
&#39;embedding&#39;} |
| Adversarial: on the same Enterprise connection the old blocking
`table.refresh_column(&#34;embedding&#34;)` fails with
NotImplementedError naming refresh_column_async and sends no request | ✅
pass | live | driver-output-round2.txt: RAISED NotImplementedError: ...
use refresh_column_async and wait on the returned handle; requests sent:
[] |
| The create-function.mdx refresh example as now written,
`refresh_column_async(&#34;embedding&#34;, gpu_class=&#34;h100&#34;,
total_gpu_count=8)` then `job.wait()`, is accepted on Enterprise and
sends both GPU options | ✅ pass | live | driver-output-round2.txt:
server received {&#39;gpu_class&#39;: &#39;h100&#39;,
&#39;total_gpu_count&#39;: 8, &#39;column&#39;: &#39;embedding&#39;} |
| The create-function.mdx `table.add_columns({&#34;embedding&#34;:
&lt;Function binding&gt;}, total_gpu_count=8)` is accepted on Enterprise
and sends the fleet GPU ceiling | ✅ pass | live |
driver-output-round2.txt: OK -&gt; AddColumnsResult(version=2); POST
/v1/table/test/add_columns/ body carries the Function binding and
&#39;total_gpu_count&#39;: 8 |
| Adversarial: the GPU arguments removed from the create-function.mdx
example (`gpu_count` on refresh_column_async; `gpu_class`/`gpu_count` on
add_columns) are rejected by the Enterprise table, matching… | ✅ pass |
live | driver-output-round2.txt: TypeError unexpected keyword argument
&#39;gpu_count&#39; (refresh_column_async) and &#39;gpu_class&#39;
(add_columns) |
| The committed `PyQuickstartAddFeature` snippet equals what the snippet
generator produces from docs/web-tests/py/test_quickstart.py | ✅ pass |
live | `mdx_snippets_gen.py` output in snippets-regen-round2; `diff -r`
against docs/web/snippets reports no difference for quickstart.mdx |
| A reader opening the five changed pages in a local Mintlify preview
sees the job form and no blocking `table.refresh_column(` call | ✅ pass
| live | rendered-round2-counts.txt and rendered-round2/*.html: all five
pages return 200 with zero blocking calls; job form present on each |
| `test_quickstart_derived_feature_on_a_deployment` passes against a
real LanceDB Enterprise deployment | ⏸️ untested | no | Ran the test; it
skips because no Enterprise deployment credentials exist here. A
localhost emulator cannot stand in: the test registers a Function over
Flight SQL and computes real values. To run it,… |
| `version = db.create_function(embed)` from the create-function.mdx
example registers a Function on Enterprise | ⏸️ untested | no | Tried it
against the emulator; the call goes over Flight SQL to a Function
catalog, which only a real Enterprise deployment provides. This line is
unchanged by the diff. Needs the same deployment cred… |

- <code>`~/.treehouse/lancedb-9ea8c9/1/lancedb/python/.venv/bin/python
drive_enterprise_refresh_v3.py` (lancedb 0.42.0b26 built at cb082c08,
whose SDK source is identical to this head; Enterprise connection to a
localhost emulator with synthetic responses)</code>
- <code>`python docs/web-tests/mdx_snippets_gen.py -s docs/web-tests/py
-s docs/web-tests/ts -s docs/web-tests/rs -o
&lt;evidence&gt;/snippets-regen-round2` then `diff -r` against
`docs/web/snippets` (quickstart.mdx identical)</code>
- <code>`cd docs/web-tests/py &amp;&amp; python -m pytest
test_quickstart.py -q -rs` (4 passed, 6 skipped; all skips are
deployment-only tests)</code>
- <code>`mint dev --port 3397` in docs/web, then `curl` of /quickstart,
/curation/vend-secret, /curation/create-function,
/enterprise/auto-refresh, /feature-engineering/add-computed-column (all
200) and a count of blocking vs job-form calls in the served HTML</code>
- <code>`git status --short` after teardown (clean; preview stopped,
port 3397 free)</code>
</details>

<details>
<summary>✅ **Document** - passed</summary>

✅ No issues found.
</details>

<details>
<summary>⚠️ **Lint** - 1 info</summary>

- ℹ️ `docs/web-tests/py/test_quickstart.py:29` - `ruff check` reports
C408 (`dict()` call, rewrite as a literal) in the `deployment` fixture.
It is on a line this change did not touch and is also present at the
base commit; ruff&#39;s only fix for it is marked unsafe, so I left it.
`ruff format --check` passes. ruff is not on PATH, so I ran it through
`uvx`, which may not be the repo-pinned version.
</details>

<details>
<summary>✅ **Push** - passed</summary>

✅ No issues found.
</details>
2026-11-24 09:31:06 -08:00

229 lines
8.8 KiB
Plaintext

---
title: "Vend a Secret to a Function"
tag: "Early access"
sidebarTitle: "Vend Secret"
description: "Bind a Secret to a Function by reference, and how its value reaches running code during SQL evaluation and refresh."
icon: key
keywords: ["secret", "udf", "function", "credential", "api key", "env_variable", "refresh"]
availability:
embedded: unavailable
enterprise: available
---
<Badge color="purple">Early access</Badge>
A Function that calls an external service needs a credential without
putting it in the function's source -- see
[Create a Function](/curation/create-function#remote) for how to register
one. A [Secret](/management/secret) is a database-scoped named credential:
you create it once, then bind it *by reference* -- by name, not by value --
when you register the Function that needs it.
## Specify the Secret when you register the Function {#specify}
Store the credential, then bind it to an environment variable the function's
code already reads:
<CodeGroup>
```python Python icon="python"
import os
from lancedb import EnvVarSecret, function
db.create_secret("embedding-api-key", os.environ["EMBEDDING_API_KEY"])
@function
class embed_remote:
def __init__(self, model: str = "text-embedding-3-small"):
import os
from openai import OpenAI
self.client = OpenAI(api_key=os.environ["EMBEDDING_API_KEY"])
self.model = model
def __call__(self, text: str) -> list[float]:
response = self.client.embeddings.create(input=text, model=self.model)
return response.data[0].embedding
version = db.create_function_async(
embed_remote,
secrets=[
EnvVarSecret(secret_name="embedding-api-key", env_variable="EMBEDDING_API_KEY")
],
).wait()
```
</CodeGroup>
The function's own code never names the Secret -- it reads
`EMBEDDING_API_KEY` the same way it would outside LanceDB. The binding, in
`secrets=[...]`, is what connects that variable to the stored credential.
It is checked for shape at registration (valid variable name, not reserved,
not repeated) but not resolved yet: the Secret does not have to exist until
a column actually uses this Function version, so you can create the
Function and its Secret in either order.
## Hugging Face models {#hugging-face}
For a model loaded from the Hugging Face Hub, store the token as a Secret
and bind it to the variable the Hub client reads. Use a class Function so
the model is loaded once per remote instance rather than once per row:
```python
import os
from lancedb import EnvVarSecret, col, function
db.create_secret("hf-token", os.environ["HF_TOKEN"])
@function(
name="embed_text",
pip=["sentence-transformers==3.3.1"],
)
class EmbedText:
def __init__(self, revision: str):
from sentence_transformers import SentenceTransformer
self.model = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2",
revision=revision,
)
def __call__(self, text: str) -> list[float]:
return self.model.encode(text).tolist()
embed_fn = db.create_function(
EmbedText,
secrets=[EnvVarSecret(secret_name="hf-token", env_variable="HF_TOKEN")],
)
table = db.open_table("documents")
table.add_columns(
{
"embedding": embed_fn(
text=col("text"),
revision="<full-40-character-commit-sha>",
)
}
)
job = table.refresh_column_async("embedding")
job.wait()
```
A decorated class calls `__init__` once per remote instance and `__call__`
for each row or batch. The class's `__init__` parameters are binding
initialization values, so `revision` is fixed for this binding and the
model is reused for all rows handled by that instance. Instances are not
shared across workers.
Use a full 40-character commit SHA for `revision`. A branch or tag can
move; a commit pins the model version. See the official Hugging Face
documentation for
[`HF_TOKEN`](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hftoken)
and
[downloading a specific revision](https://huggingface.co/docs/huggingface_hub/guides/download#revision).
`HF_TOKEN` authenticates Hub requests, but a cached model and a pinned
revision are not a guarantee of offline execution. The Hub client may
still request metadata or missing files, and authentication does not
guarantee that requests will avoid rate limits.
## How the value reaches a running evaluation {#delivery}
The Secret's value is resolved fresh for each job, never read once and
cached in the Function's definition:
| Step | What happens |
| --- | --- |
| `add_columns` with this Function version | Every bound Secret must now exist. The column pins this exact version, not a value. |
| A refresh starts: `refresh_column_async`, or a materialized view's refresh | Every bound Secret must still exist, checked before any row is computed. |
| The job captures each bound Secret's current value | LanceDB looks up the value once, when the job starts, and sets it as that environment variable for every row the job evaluates, including its retries. No other environment variable carries over. |
This is why rotating a Secret needs no new Function version and no column
change: `alter_secret` changes the value a *future* lookup returns. The
agent captures that value once, when a job starts, and reuses its own
captured copy for that job's full run and any of its retries -- a refresh
already running keeps the value it started with for every row, and only a
job that starts *after* the rotation sees the new one.
### Rotate and revoke {#rotation}
`alter_secret` and `drop_secret` never interrupt work in progress, so a
routine rotation cannot fail a backfill halfway through:
| Action | Running jobs | Next job | New Function version? |
| --- | --- | --- | --- |
| `alter_secret` | A running job and its retries keep the value captured at start; only a new job gets the latest value | Uses the latest value | No |
| `drop_secret` | Run to completion on the last value | Refused, naming the Secret | No |
| Revoke the key at its provider | Fails on their next call to the provider | Fails until a new value is set | No |
| Re-create a dropped name | Keeps the dropped Secret's last value | Picks up the new Secret | No |
Because a rotation creates no new Function version, it also reaches columns
pinned to a version registered before it. Binding a Function to a
*different* Secret or variable does register a new version, and existing
columns keep the binding they were declared with.
<Warning>
To stop a credential from being used **now**, revoke it at its provider,
for example by deleting the key in the OpenAI console. A value already
handed to a running job cannot be recalled.
</Warning>
`drop_secret` cannot be undone, and it does not check for Functions still
bound to the Secret.
<Note>
Reading a column this Function already filled needs only `SELECT` on the
table. No Function runs on the read path, so a reader needs no grant on the
Function or its Secrets -- only someone triggering a refresh does.
</Note>
## Vending during SQL evaluation specifically {#sql}
A computed column's expression and a `CREATE MATERIALIZED VIEW` query both
plan and execute as SQL, so a Function called from either one is vended its
Secrets the same way: at the evaluation that fills the column or refreshes
the view, not at declaration time.
<CodeGroup>
```sql SQL icon="database"
CREATE MATERIALIZED VIEW frames_captioned AS
SELECT f.frame_id, caption(f.jpeg) AS caption
FROM frames f
```
</CodeGroup>
`caption` here is a Function bound to a Secret through the Python SDK when
it was registered -- SQL has no syntax for the binding itself, only for
calling the already-registered Function. The `CREATE MATERIALIZED VIEW`
statement's initial population, and every `REFRESH MATERIALIZED VIEW`
after it, each look up the bound Secret's current value independently.
## Troubleshooting {#troubleshooting}
**403 when adding or refreshing a Function column**: you need `USAGE` on
the Function *and* on every Secret it binds, in addition to the table
privilege. The error names the object you are missing.
**The Function runs but its provider rejects the key**: a misspelled
*environment variable* cannot be caught at registration, because nothing
knows which variables a Function reads. Check that `env_variable` matches
what the Function's code reads, such as `EMBEDDING_API_KEY` above.
## Related guides {#next}
<CardGroup cols={2}>
<Card title="Create a Function" icon="code" href="/curation/create-function#remote">
Write the function that reads the credential.
</Card>
<Card title="Secret" icon="key" href="/management/secret">
Create, rotate, list and drop the credential itself.
</Card>
<Card title="Privileges" icon="key" href="/governance/privileges#sql">
Grant and revoke privileges on a Secret.
</Card>
<Card title="Refresh a computed column" icon="arrows-rotate" href="/feature-engineering/refresh-column">
Running the evaluation that vends the Secret.
</Card>
</CardGroup>