Skip to content

fix(python): keep embedding functions registered without an alias readable - #4356

Open
MohammadHijjawi97 wants to merge 1 commit into
lancedb:mainfrom
MohammadHijjawi97:fix/python-embedding-registry-default-name
Open

MohammadHijjawi97 wants to merge 1 commit into
lancedb:mainfrom
MohammadHijjawi97:fix/python-embedding-registry-default-name

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

EmbeddingFunctionRegistry.register() documents that the class name is used when no alias is given, and it does register the class under that name. But it stored the alias itself (None) as __embedding_function_registry_alias__, which is what function_to_metadata() writes into the table schema. A table using such a function gets "name": null in its embedding_functions metadata, and any later read of the functions fails:

@get_registry().register()
class MyEmbed(TextEmbeddingFunction): ...

f = MyEmbed.create()
class Schema(LanceModel):
    text: str = f.SourceField()
    vector: Vector(4) = f.VectorField()

tbl = db.create_table("t", schema=Schema)
tbl.add([{"text": "hi"}])   # KeyError: None
tbl.search("hi")            # KeyError: None

This stores the key the class is registered under instead, so the class name round-trips. For aliased classes the key is the alias, so their metadata is unchanged. The TypeScript registry already falls back to ctor.name in the same way.

Added test_embedding_function_registered_without_alias, which creates a table with such a function, reopens it, and adds a row. It fails with KeyError before the change. test_embeddings.py, test_pydantic.py, test_table.py and test_db.py pass, and ruff format --check / ruff check are clean.

…dable

`EmbeddingFunctionRegistry.register()` looks the class up under its class
name when no alias is given, but stored `None` as the name that gets
written into the table metadata. Tables using such a function were
written with `"name": null`, and reading their embedding functions back
failed with `KeyError: None`, which broke `add()` and `search()` on the
table.

Store the key the class is registered under instead, which is what the
TypeScript registry already does.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added bug Something isn't working Python Python SDK labels Sep 30, 2026

@lancedb-gatekeeper lancedb-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

Storing the resolved registration key restores the documented class-name round-trip while preserving explicit aliases. The regression and local metadata checks verified reopening, embedding generation, text search, and reading newly written metadata with the previous parser.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance. Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant