{"record":{"id":"e801be4a1dddc6b8","repo":"chroma-core/chroma","slug":"embedding-function-must-have-a-name-to-be-register","errorCode":null,"errorMessage":"Embedding function must have a name to be registered.","messagePattern":"Embedding function must have a name to be registered\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/registry.ts","lineNumber":10,"sourceCode":"import type { EmbeddingFunctionConstructor } from \"./IEmbeddingFunction\";\nimport * as allEmbeddingFunctions from \"./all\";\n\nconst knownEmbeddingFunctions = new Map<string, EmbeddingFunctionConstructor>(\n  Object.values(allEmbeddingFunctions).map((fn) => [fn.name, fn]),\n);\n\nexport const registerEmbeddingFunction = (fn: EmbeddingFunctionConstructor) => {\n  if (!fn.name) {\n    throw new Error(\"Embedding function must have a name to be registered.\");\n  }\n\n  knownEmbeddingFunctions.set(fn.name, fn);\n};\n\nexport const getEmbeddingFunction = (name: string) => {\n  const fn = knownEmbeddingFunctions.get(name);\n  if (!fn) {\n    throw new Error(`Embedding function ${name} not found`);\n  }\n  return fn;\n};\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/registry.ts#L1-L23","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nregisterEmbeddingFunction(class {\n  name = \"my-embed\";\n  async generate(texts: string[]) { /* ... */ return [[0]]; }\n}); // anonymous class -> fn.name === \"\" -> throws\n\n// after\nclass MyEmbedding {\n  name = \"my-embed\";\n  async generate(texts: string[]) { /* ... */ return texts.map(() => [0]); }\n}\nregisterEmbeddingFunction(MyEmbedding);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const isNameableConstructor = (\n  fn: EmbeddingFunctionConstructor,\n): fn is EmbeddingFunctionConstructor & { name: string } => typeof fn?.name === \"string\" && fn.name.length > 0;\n\n// usage\nif (!isNameableConstructor(MyEmbedding)) {\n  throw new Error(\"Embedding function class lost its name (anonymous class or minifier) — declare it named and enable keep_fnames.\");\n}\nregisterEmbeddingFunction(MyEmbedding);","tryCatchPattern":null,"preventionTips":["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."],"tags":["registry","embeddings","function-name","bundling","minification"],"backgroundTag":"missing-function-name","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}