microsoft/semantic-kernel · error · ServiceInitializationError
Ollama embedding model ID is not set.
Error message
Ollama embedding model ID is not set.
What it means
Thrown by the OllamaTextEmbedding constructor when the resolved embedding_model_id is empty or None after merging the ai_model_id argument with the OLLAMA_EMBEDDING_MODEL_ID environment variable. Without a model identifier the service cannot call the Ollama /api/embeddings endpoint, so it aborts. Raised as ServiceInitializationError before any network call.
Source
Thrown at python/semantic_kernel/connectors/ai/ollama/services/ollama_text_embedding.py:69
ai_model_id (Optional[str]): The model name. (Optional)
host (Optional[str]): URL of the Ollama server, defaults to None and
will use the default Ollama service address: http://127.0.0.1:11434. (Optional)
client (Optional[AsyncClient]): A custom Ollama client to use for the service. (Optional)
env_file_path (str | None): Use the environment settings file as a fallback to using env vars.
env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.
"""
try:
ollama_settings = OllamaSettings(
embedding_model_id=ai_model_id,
host=host,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise ServiceInitializationError("Failed to create Ollama settings.", ex) from ex
if not ollama_settings.embedding_model_id:
raise ServiceInitializationError("Ollama embedding model ID is not set.")
super().__init__(
service_id=service_id or ollama_settings.embedding_model_id,
ai_model_id=ollama_settings.embedding_model_id,
client=client or AsyncClient(host=ollama_settings.host),
)
@override
async def generate_embeddings(
self,
texts: list[str],
settings: "PromptExecutionSettings | None" = None,
**kwargs: Any,
) -> ndarray:
raw_embeddings = await self.generate_raw_embeddings(texts, settings, **kwargs)
return array(raw_embeddings)
@overrideView on GitHub (pinned to c028a0c7dc)
Solutions
- Pass the model name directly: OllamaTextEmbedding(ai_model_id='nomic-embed-text')
- Set the env var: export OLLAMA_EMBEDDING_MODEL_ID=nomic-embed-text
- Add OLLAMA_EMBEDDING_MODEL_ID to your .env and pass env_file_path
- Ensure the embedding model is pulled: ollama pull nomic-embed-text
Example fix
// before embedder = OllamaTextEmbedding() // after embedder = OllamaTextEmbedding(ai_model_id='nomic-embed-text')
Defensive patterns
Strategy: validation
Validate before calling
import os
model_id = 'nomic-embed-text'
if not model_id and not os.environ.get('OLLAMA_EMBEDDING_MODEL_ID'):
raise RuntimeError('OLLAMA_EMBEDDING_MODEL_ID is not set and no ai_model_id provided')
from semantic_kernel.connectors.ai.ollama import OllamaTextEmbedding
embedder = OllamaTextEmbedding(ai_model_id=model_id) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
try:
embedder = OllamaTextEmbedding()
except ServiceInitializationError as e:
if 'embedding model ID' in str(e):
embedder = OllamaTextEmbedding(ai_model_id=os.environ['FALLBACK_EMBEDDING_MODEL'])
else:
raise Prevention
- Set OLLAMA_EMBEDDING_MODEL_ID in your .env from the start
- Pull the embedding model before first use: ollama pull nomic-embed-text
- Validate required embedding config at application startup
When it happens
Trigger: Constructing OllamaTextEmbedding() with ai_model_id omitted while OLLAMA_EMBEDDING_MODEL_ID is not set in the environment or .env file. Also triggered by passing ai_model_id=None explicitly.
Common situations: New project with no .env configured; using a shared OLLAMA_HOST but forgetting the model-id env var; env var name typo (OLLAMA_EMBEDDING_MODEL instead of OLLAMA_EMBEDDING_MODEL_ID); pulling a text model but not an embedding model (ollama pull nomic-embed-text).
Related errors
- The Vertex AI embedding model ID is required.
- Ollama text model ID is required.
- The Amazon Bedrock Text Embedding Model ID is missing.
- The Google AI Gemini model ID is required.
- The Google AI embedding model ID is required.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/389aab10139690dd.
Report an issue: GitHub.