chroma-core/chroma · error · Error
Embedding function must have a name to be registered.
Error message
Embedding function must have a name to be registered.
What it means
registerEmbeddingFunction() inserts custom embedding functions into a Map keyed by the constructor's `name` property (for built-ins this is the class name, e.g. 'TogetherAIEmbeddingFunction'). It refuses constructors with an empty name — anonymous class expressions passed inline, or functions whose names were stripped by minification (terser keep_fnames: false, aggressive bundler mangling).
Source
Thrown at clients/js/packages/chromadb-core/src/embeddings/registry.ts:10
import type { EmbeddingFunctionConstructor } from "./IEmbeddingFunction";
import * as allEmbeddingFunctions from "./all";
const knownEmbeddingFunctions = new Map<string, EmbeddingFunctionConstructor>(
Object.values(allEmbeddingFunctions).map((fn) => [fn.name, fn]),
);
export const registerEmbeddingFunction = (fn: EmbeddingFunctionConstructor) => {
if (!fn.name) {
throw new Error("Embedding function must have a name to be registered.");
}
knownEmbeddingFunctions.set(fn.name, fn);
};
export const getEmbeddingFunction = (name: string) => {
const fn = knownEmbeddingFunctions.get(name);
if (!fn) {
throw new Error(`Embedding function ${name} not found`);
}
return fn;
};
View on GitHub (pinned to aecdd12c8a)
Solutions
- Declare the class with a name and register the named binding: `class MyEmbedding implements IEmbeddingFunction { name = 'my-embed'; ... }` then registerEmbeddingFunction(MyEmbedding).
- Configure your bundler to preserve names: terser { compress: { keep_fnames: true }, mangle: { keep_fnames: true } }, esbuild --keep-names.
- Remember the registry key is the class name — choose it deliberately since later lookups use it.
Example fix
// before
registerEmbeddingFunction(class {
name = "my-embed";
async generate(texts: string[]) { /* ... */ return [[0]]; }
}); // anonymous class -> fn.name === "" -> throws
// after
class MyEmbedding {
name = "my-embed";
async generate(texts: string[]) { /* ... */ return texts.map(() => [0]); }
}
registerEmbeddingFunction(MyEmbedding); Defensive patterns
Strategy: type-guard
Type guard
const isNameableConstructor = (
fn: EmbeddingFunctionConstructor,
): fn is EmbeddingFunctionConstructor & { name: string } => typeof fn?.name === "string" && fn.name.length > 0;
// usage
if (!isNameableConstructor(MyEmbedding)) {
throw new Error("Embedding function class lost its name (anonymous class or minifier) — declare it named and enable keep_fnames.");
}
registerEmbeddingFunction(MyEmbedding); Prevention
- Always register named class declarations, never inline anonymous class expressions.
- Enable keep-names/keep_fnames in the production build if registration happens in bundled code.
- Cover custom embedding function registration with a smoke test that runs against the built bundle.
When it happens
Trigger: registerEmbeddingFunction(class { ... }) with an anonymous class expression; registering a factory result or arrow function that lost its name; a production bundle where class names were mangled to single characters.
Common situations: Registering custom embedding functions for config deserialization; minified frontend/serverless builds where names are dropped; code that wraps classes via higher-order functions returning anonymous classes.
Related errors
- Embedding function ${name} not found
- Cloudflare API key is required. Please provide it in the con
- resp.detail || "Unknown error"
- Error calling Cloudflare Workers AI API: ${error.message}
- Error calling Cloudflare Workers AI API: ${error}
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/e801be4a1dddc6b8.
Report an issue: GitHub.