mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
docs: use function instead of deprecated udf in examples (#5027)
`lancedb.udf` is a deprecated alias of `lancedb.function` and emits a `DeprecationWarning`. This switches the quickstart and the curation examples to `function`, so readers who copy them no longer see the warning. The quickstart snippet is regenerated from its test.
This commit is contained in:
@@ -350,9 +350,9 @@ def test_quickstart_derived_feature(db_path_factory):
|
||||
flatten_stats(table)
|
||||
|
||||
# --8<-- [start:quickstart_add_feature]
|
||||
from lancedb import col, udf
|
||||
from lancedb import col, function
|
||||
|
||||
@udf
|
||||
@function
|
||||
def quality_score(
|
||||
motion: float, sharpness: float, exposure: float, framing: float
|
||||
) -> float:
|
||||
@@ -385,9 +385,9 @@ def test_quickstart_derived_feature_on_a_deployment(deployment):
|
||||
table = create_frames(deployment)
|
||||
flatten_stats(table)
|
||||
|
||||
from lancedb import col, udf
|
||||
from lancedb import col, function
|
||||
|
||||
@udf
|
||||
@function
|
||||
def quality_score(
|
||||
motion: float, sharpness: float, exposure: float, framing: float
|
||||
) -> float:
|
||||
|
||||
@@ -144,9 +144,9 @@ same way any other curation Function is registered:
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
from lancedb import udf
|
||||
from lancedb import function
|
||||
|
||||
@udf
|
||||
@function
|
||||
def caption_quality(caption: str) -> float:
|
||||
... # score the caption, e.g. with a lightweight heuristic or model
|
||||
|
||||
|
||||
@@ -114,9 +114,9 @@ matched rows, not before. Register `caption_quality` first:
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
from lancedb import udf
|
||||
from lancedb import function
|
||||
|
||||
@udf
|
||||
@function
|
||||
def caption_quality(caption: str) -> float:
|
||||
... # score the caption, e.g. with a lightweight heuristic or model
|
||||
|
||||
|
||||
@@ -159,9 +159,9 @@ before running it over the whole table. Register `caption_quality` first:
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
from lancedb import udf
|
||||
from lancedb import function
|
||||
|
||||
@udf
|
||||
@function
|
||||
def caption_quality(caption: str) -> float:
|
||||
... # score the caption, e.g. with a lightweight heuristic or model
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ code already reads:
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
import os
|
||||
from lancedb import EnvVarSecret, udf
|
||||
from lancedb import EnvVarSecret, function
|
||||
|
||||
db.create_secret("embedding-api-key", os.environ["EMBEDDING_API_KEY"])
|
||||
|
||||
@udf
|
||||
@function
|
||||
class embed_remote:
|
||||
def __init__(self, model: str = "text-embedding-3-small"):
|
||||
import os
|
||||
@@ -70,12 +70,12 @@ the model is loaded once per remote instance rather than once per row:
|
||||
```python
|
||||
import os
|
||||
|
||||
from lancedb import EnvVarSecret, col, udf
|
||||
from lancedb import EnvVarSecret, col, function
|
||||
|
||||
db.create_secret("hf-token", os.environ["HF_TOKEN"])
|
||||
|
||||
|
||||
@udf(
|
||||
@function(
|
||||
name="embed_text",
|
||||
pip=["sentence-transformers==3.3.1"],
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
export const PyQuickstartAddData = "table.add(\n [\n {\n \"frame_id\": \"4\",\n \"video_id\": \"clip-2\",\n \"caption\": \"a gripper lowering a cup onto the table\",\n \"stats\": {\"motion\": 5, \"sharpness\": 4, \"exposure\": 4, \"framing\": 2},\n \"embedding\": [0.3, 0.9, 0.6, 0.8],\n }\n ]\n)\n";
|
||||
|
||||
export const PyQuickstartAddFeature = "from lancedb import col, udf\n\n@udf\ndef quality_score(\n motion: float, sharpness: float, exposure: float, framing: float\n) -> float:\n return (motion + sharpness + exposure + framing) / 4.0\n\nversion = db.create_function_async(quality_score).wait()\ntable.add_columns(\n {\n \"quality_score\": version(\n motion=col(\"motion\"),\n sharpness=col(\"sharpness\"),\n exposure=col(\"exposure\"),\n framing=col(\"framing\"),\n )\n }\n)\ntable.refresh_column(\"quality_score\")\n";
|
||||
export const PyQuickstartAddFeature = "from lancedb import col, function\n\n@function\ndef quality_score(\n motion: float, sharpness: float, exposure: float, framing: float\n) -> float:\n return (motion + sharpness + exposure + framing) / 4.0\n\nversion = db.create_function_async(quality_score).wait()\ntable.add_columns(\n {\n \"quality_score\": version(\n motion=col(\"motion\"),\n sharpness=col(\"sharpness\"),\n exposure=col(\"exposure\"),\n framing=col(\"framing\"),\n )\n }\n)\ntable.refresh_column(\"quality_score\")\n";
|
||||
|
||||
export const PyQuickstartAddFeatureEnterprise = "job = table.refresh_column_async(\"quality_score\")\njob.wait()\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user