{"record":{"id":"7de574dac0ebf610","repo":"microsoft/autogen","slug":"failed-to-create-sentencetransformer-embedding-fun","errorCode":null,"errorMessage":"Failed to create SentenceTransformer embedding function with model '{config.model_name}'. Ensure sentence-transformers is installed and the model is available. Error: {e}","messagePattern":"Failed to create SentenceTransformer embedding function with model '(.+?)'\\. Ensure sentence-transformers is installed and the model is available\\. Error: (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py","lineNumber":215,"sourceCode":"            ImportError: If required dependencies are not installed.\n        \"\"\"\n        try:\n            from chromadb.utils import embedding_functions\n        except ImportError as e:\n            raise ImportError(\n                \"ChromaDB embedding functions not available. Ensure chromadb is properly installed.\"\n            ) from e\n\n        config = self._config.embedding_function_config\n\n        if isinstance(config, DefaultEmbeddingFunctionConfig):\n            return embedding_functions.DefaultEmbeddingFunction()\n\n        elif isinstance(config, SentenceTransformerEmbeddingFunctionConfig):\n            try:\n                return embedding_functions.SentenceTransformerEmbeddingFunction(model_name=config.model_name)\n            except Exception as e:\n                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","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py#L197-L233","documentation":"When the memory is configured with SentenceTransformerEmbeddingFunctionConfig, construction of the sentence-transformers embedding function is wrapped in a try/except; any failure (package missing, model download failure, model name typo) is re-raised as ImportError including the model name and the underlying error.","triggerScenarios":"Configuring ChromaDBVectorMemory with SentenceTransformerEmbeddingFunctionConfig(model_name=...) and initializing it when sentence-transformers is not installed, the model name is invalid, or the machine cannot reach the HuggingFace hub to download the model.","commonSituations":"Offline/air-gapped environments; corporate proxies blocking huggingface.co; model name typos like 'all-MiniLM-L6-v2' vs 'sentence-transformers/all-MiniLM-L6-v2'; missing torch/onnxruntime.","solutions":["Install sentence-transformers: pip install sentence-transformers.","Verify the exact model name exists on HuggingFace and matches what you passed.","In offline environments, pre-download the model (huggingface-cli download or set HF_HOME) and set HF_HUB_OFFLINE=1.","Read the trailing 'Error: {e}' in the message for the root cause (network vs missing module)."],"exampleFix":"# before\nconfig = SentenceTransformerEmbeddingFunctionConfig(model_name=\"minilm\")\n# after\npip install sentence-transformers\nconfig = SentenceTransformerEmbeddingFunctionConfig(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")","handlingStrategy":"try-catch","validationCode":"try:\n    import sentence_transformers  # noqa: F401\nexcept ImportError:\n    raise SystemExit(\"pip install sentence-transformers\")\n# optionally pre-download the model for offline use\n# huggingface-cli download sentence-transformers/all-MiniLM-L6-v2","typeGuard":null,"tryCatchPattern":"try:\n    memory = ChromaDBVectorMemory(config=config_with_st)\nexcept ImportError as e:\n    if \"SentenceTransformer\" in str(e):\n        # missing package, bad model name, or network failure — message carries Error: {cause}\n        raise SystemExit(f\"Fix embedding setup: {e}\") from e\n    raise","preventionTips":["Install sentence-transformers and pre-download models for offline/air-gapped runs.","Use fully qualified model ids (sentence-transformers/...).","Configure HF_HOME and proxies so model downloads succeed in restricted networks."],"tags":["autogen","chromadb","embeddings","sentence-transformers","network"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}