microsoft/semantic-kernel · error · ServiceInitializationError
Error: Azure Cognitive Search credentials not set.
Error message
Error: Azure Cognitive Search credentials not set.
What it means
Defensive guard in `get_search_index_async_client`: after the credential-resolution block, it asserts that at least one of `azure_credential`/`token_credential` is non-None, raising `ServiceInitializationError` otherwise. Under the current if/elif/else flow this is largely unreachable because the `else` branch (error 1373) already raises when nothing is supplied; it protects against a regression where credentials end up None unexpectedly.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py:69
if service_endpoint is None:
print(service_endpoint)
raise ServiceInitializationError("Error: Azure Cognitive Search client not set.")
# Credentials
if admin_key:
azure_credential = AzureKeyCredential(admin_key)
elif azure_credential:
azure_credential = azure_credential
elif token_credential:
token_credential = token_credential
elif os.getenv(ENV_VAR_API_KEY):
azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY))
else:
raise ServiceInitializationError("Error: missing Azure Cognitive Search client credentials.")
if azure_credential is None and token_credential is None:
raise ServiceInitializationError("Error: Azure Cognitive Search credentials not set.")
sk_headers = {USER_AGENT: "Semantic-Kernel"}
if azure_credential:
return SearchIndexClient(endpoint=service_endpoint, credential=azure_credential, headers=sk_headers)
if token_credential:
return SearchIndexClient(endpoint=service_endpoint, credential=token_credential, headers=sk_headers)
raise ValueError("Error: unable to create Azure Cognitive Search client.")
def get_index_schema(vector_size: int, vector_search_profile_name: str) -> list:
"""Return the schema of search indexes.
Args:
vector_size (int): The size of the vectors being stored in collection/index.
vector_search_profile_name (str): The name of the vector search profile.View on GitHub (pinned to c028a0c7dc)
Solutions
- Provide a valid `admin_key`, `azure_credential`, or `token_credential` (or `AZURE_COGNITIVE_SEARCH_ADMIN_KEY`) so resolution succeeds at the earlier branches.
- If encountered unexpectedly, audit any monkeypatching of the credential arguments or the factory.
- Report as a bug if reached during normal configuration.
Defensive patterns
Strategy: validation
Validate before calling
# Defensive/unreachable under normal flow; ensure a credential object is truthy. assert azure_credential or token_credential, "credential objects unexpectedly None"
Type guard
def has_resolved_credential(azure_credential, token_credential) -> bool:
return bool(azure_credential) or bool(token_credential) Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
client = get_search_index_async_client(...)
except ServiceInitializationError as e:
if "credentials not set" in str(e):
raise SystemExit("credential resolution regression; supply valid credential") from e
raise Prevention
- Pass a valid credential object so the normal path is taken.
- Audit any monkeypatching of credential arguments.
- Treat encountering this branch as a regression/bug.
When it happens
Trigger: Reachable only if the credential assignment logic is altered so both variables remain None while skipping the `else` raise, or via unusual monkeypatching. Under normal control flow it does not fire because error 1373 fires first.
Common situations: Test harness patching credential objects to None; a refactor breaking the credential branches; passing a falsy credential object that the branches skip.
Related errors
- Error: unable to create Azure Cognitive Search client.
- Error: self._search_index_client not set 1.
- Error: Azure Cognitive Search client not set.
- Error: missing Azure Cognitive Search client credentials.
- Failed to create Azure Cognitive Search settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/04844cae2d038eea.
Report an issue: GitHub.