{"record":{"id":"435fa71076db130f","repo":"microsoft/autogen","slug":"failed-to-create-custom-embedding-function-error","errorCode":null,"errorMessage":"Failed to create custom embedding function. Error: {e}","messagePattern":"Failed to create custom embedding function\\. Error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py","lineNumber":233,"sourceCode":"                raise ImportError(\n                    f\"Failed to create SentenceTransformer embedding function with model '{config.model_name}'. \"\n                    f\"Ensure sentence-transformers is installed and the model is available. Error: {e}\"\n                ) from e\n\n        elif isinstance(config, OpenAIEmbeddingFunctionConfig):\n            try:\n                return embedding_functions.OpenAIEmbeddingFunction(api_key=config.api_key, model_name=config.model_name)\n            except Exception as e:\n                raise ImportError(\n                    f\"Failed to create OpenAI embedding function with model '{config.model_name}'. \"\n                    f\"Ensure openai is installed and API key is valid. Error: {e}\"\n                ) from e\n\n        elif isinstance(config, CustomEmbeddingFunctionConfig):\n            try:\n                return config.function(**config.params)\n            except Exception as e:\n                raise ValueError(f\"Failed to create custom embedding function. Error: {e}\") from e\n\n        else:\n            raise ValueError(f\"Unsupported embedding function config type: {type(config)}\")\n\n    def _ensure_initialized(self) -> None:\n        \"\"\"Ensure ChromaDB client and collection are initialized.\"\"\"\n        if self._client is None:\n            try:\n                from chromadb.config import Settings\n\n                settings = Settings(allow_reset=self._config.allow_reset)\n\n                if isinstance(self._config, PersistentChromaDBVectorMemoryConfig):\n                    self._client = PersistentClient(\n                        path=self._config.persistence_path,\n                        settings=settings,\n                        tenant=self._config.tenant,\n                        database=self._config.database,","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py#L215-L251","documentation":"CustomEmbeddingFunctionConfig lets you supply an arbitrary callable plus params; it is invoked as config.function(**config.params) inside a try/except, and any exception it raises is re-raised as ValueError with the original error chained. This reports failures in user-supplied embedding factory code.","triggerScenarios":"Configuring CustomEmbeddingFunctionConfig whose function raises on invocation: mismatched params (unexpected keyword), missing required args, or the function itself erroring (e.g. loading a local model that does not exist).","commonSituations":"Param names in the config not matching the callable signature; callables expecting positional args; custom embedding code failing at construction (missing model files, wrong device).","solutions":["Read the trailing 'Error: {e}' — it carries the exception your function raised.","Make the params dict keys exactly match the callable's keyword parameter names.","Test the callable standalone: config.function(**config.params) in a REPL before wiring it into the memory.","Fix the root cause inside your custom embedding function (missing file, bad device, etc.)."],"exampleFix":"# before\ndef make_embedder(model_path): ...\nconfig = CustomEmbeddingFunctionConfig(function=make_embedder, params={\"path\": \"model.bin\"})\n# after\nconfig = CustomEmbeddingFunctionConfig(function=make_embedder, params={\"model_path\": \"model.bin\"})","handlingStrategy":"try-catch","validationCode":"# smoke-test the factory before wiring it into memory\ntry:\n    fn = config.function(**config.params)\nexcept Exception as e:\n    raise RuntimeError(f\"custom embedding factory broken: {e}\") from e","typeGuard":"import inspect\n\ndef params_match_signature(func, params: dict) -> bool:\n    sig = inspect.signature(func)\n    try:\n        sig.bind(**params)\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    memory = ChromaDBVectorMemory(config=config)\n    await memory.update_context(ctx)\nexcept ValueError as e:\n    if \"custom embedding function\" in str(e):\n        # inspect e.__cause__ for the factory's own error and fix params/function\n        raise\n    raise","preventionTips":["Bind params against the callable's signature with inspect.signature before use.","Unit-test custom embedding factories standalone before integrating."],"tags":["autogen","chromadb","embeddings","custom-function","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}