{"record":{"id":"0bb4a22770284277","repo":"microsoft/semantic-kernel","slug":"failed-to-create-ollama-settings-0bb4a2","errorCode":null,"errorMessage":"Failed to create Ollama settings.","messagePattern":"Failed to create Ollama settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_text_embedding.py","lineNumber":66,"sourceCode":"\n        Args:\n            service_id (Optional[str]): Service ID tied to the execution settings. (Optional)\n            ai_model_id (Optional[str]): The model name. (Optional)\n            host (Optional[str]): URL of the Ollama server, defaults to None and\n                will use the default Ollama service address: http://127.0.0.1:11434. (Optional)\n            client (Optional[AsyncClient]): A custom Ollama client to use for the service. (Optional)\n            env_file_path (str | None): Use the environment settings file as a fallback to using env vars.\n            env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.\n        \"\"\"\n        try:\n            ollama_settings = OllamaSettings(\n                embedding_model_id=ai_model_id,\n                host=host,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create Ollama settings.\", ex) from ex\n\n        if not ollama_settings.embedding_model_id:\n            raise ServiceInitializationError(\"Ollama embedding model ID is not set.\")\n\n        super().__init__(\n            service_id=service_id or ollama_settings.embedding_model_id,\n            ai_model_id=ollama_settings.embedding_model_id,\n            client=client or AsyncClient(host=ollama_settings.host),\n        )\n\n    @override\n    async def generate_embeddings(\n        self,\n        texts: list[str],\n        settings: \"PromptExecutionSettings | None\" = None,\n        **kwargs: Any,\n    ) -> ndarray:\n        raw_embeddings = await self.generate_raw_embeddings(texts, settings, **kwargs)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_text_embedding.py#L48-L84","documentation":"Raised by the OllamaTextEmbedding constructor when OllamaSettings(...) raises a Pydantic ValidationError during settings construction. This is a wrapper that preserves the original validation error via 'from ex'. It indicates a structural problem with the settings (bad host URL format, wrong types) rather than a missing value.","triggerScenarios":"Constructing OllamaTextEmbedding with a malformed host (e.g. host='not-a-url'), or an env_file_path pointing at a corrupt/unreadable .env file, or an OLLAMA_HOST value that fails HttpsUrl validation.","commonSituations":"Setting OLLAMA_HOST to a bare hostname without scheme (e.g. 'localhost:11434' instead of 'http://localhost:11434'); pointing env_file_path to a non-existent file; encoding mismatch in the .env file.","solutions":["Inspect the chained ValidationError in the exception traceback for the specific field that failed","Fix the malformed setting — typically provide a full URL for host (http://127.0.0.1:11434)","Verify env_file_path exists and is readable with the correct encoding"],"exampleFix":"// before\nollama = OllamaTextEmbedding(host='localhost:11434')\n// after\nollama = OllamaTextEmbedding(host='http://127.0.0.1:11434')","handlingStrategy":"validation","validationCode":"from pydantic import TypeAdapter\nfrom semantic_kernel.connectors.ai.ollama.ollama_settings import OllamaSettings\n\n# Pre-validate host is a proper URL before constructing\nhost = 'http://127.0.0.1:11434'\nassert host.startswith('http'), 'Ollama host must include scheme (http:// or https://)'\n\nollama = OllamaTextEmbedding(host=host, ai_model_id='nomic-embed-text')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    ollama = OllamaTextEmbedding(host=host)\nexcept ServiceInitializationError as e:\n    logger.error('Settings validation failed: %s (cause: %s)', e, e.__cause__)\n    raise","preventionTips":["Always include the scheme (http:// or https://) in the host URL","Test .env file readability before passing env_file_path","Validate host URLs with a URI validator before constructing the service"],"tags":["ollama","configuration","settings-validation","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}