{"record":{"id":"d7086d2251d661d3","repo":"microsoft/semantic-kernel","slug":"failed-to-create-azure-cognitive-search-client-for","errorCode":null,"errorMessage":"Failed to create Azure Cognitive Search client for collection {collection_name}.","messagePattern":"Failed to create Azure Cognitive Search client for collection (.+?)\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":163,"sourceCode":"\n    api_key: SecretStr | None = None\n    endpoint: HttpsUrl\n    index_name: str | None = None\n\n\ndef _get_search_client(\n    endpoint: str,\n    collection_name: str | None,\n    credential: \"AzureKeyCredential | AsyncTokenCredential\",\n    **kwargs: Any,\n) -> SearchClient:\n    \"\"\"Create a search client for a collection.\"\"\"\n    if not collection_name:\n        raise VectorStoreInitializationException(\"Collection name is required to create a search client.\")\n    try:\n        return SearchClient(endpoint, collection_name, credential, **kwargs)\n    except ValueError as exc:\n        raise VectorStoreInitializationException(\n            f\"Failed to create Azure Cognitive Search client for collection {collection_name}.\"\n        ) from exc\n\n\ndef _resolve_credential(\n    azure_ai_search_settings: AzureAISearchSettings,\n    azure_credential: AzureKeyCredential | None = None,\n    token_credential: \"AsyncTokenCredential | None\" = None,\n) -> \"AzureKeyCredential | AsyncTokenCredential\":\n    \"\"\"Resolve the credential to use for Azure AI Search.\n\n    Args:\n        azure_ai_search_settings: Azure AI Search settings.\n        azure_credential: Optional Azure credentials (default: {None}).\n        token_credential: Optional Token credential (default: {None}).\n    \"\"\"\n    if azure_credential:\n        return azure_credential","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L145-L181","documentation":"Raised by _get_search_client when the Azure SearchClient constructor itself throws ValueError. The helper catches ValueError from SearchClient(endpoint, collection_name, credential, **kwargs) and re-wraps it as VectorStoreInitializationException with the collection name, chaining the original as __cause__. The concrete reason is on the cause.","triggerScenarios":"The azure.search.documents SearchClient rejected its arguments: an invalid endpoint string (not a valid URL), an incompatible credential type for the endpoint, or malformed **kwargs that the client constructor validates.","commonSituations":"The AZURE_AI_SEARCH_ENDPOINT is malformed or not an https URL; the endpoint is missing the scheme; the credential passed does not match what SearchClient expects (AzureKeyCredential vs token credential mismatch); kwargs contain an unsupported parameter for the installed azure-search-documents version.","solutions":["Inspect the chained cause: except VectorStoreInitializationException as e: print(e.__cause__)","Ensure endpoint is a valid https URL (e.g. https://<service>.search.windows.net)","Verify the credential matches the endpoint type and that AZURE_AI_SEARCH_API_KEY/credential resolution is correct","Update/align the azure-search-documents package version if kwargs are version-specific"],"exampleFix":"# before\n_get_search_client(endpoint=\"not-a-url\", collection_name=\"idx\", credential=cred)\n# raises: Failed to create Azure Cognitive Search client for collection idx.\n\n# after\n_get_search_client(\n    endpoint=\"https://mysvc.search.windows.net\",\n    collection_name=\"idx\",\n    credential=cred,\n)","handlingStrategy":"try-catch","validationCode":"from urllib.parse import urlparse\n\nif not urlparse(endpoint).scheme.startswith(\"http\"):\n    raise ValueError(f\"endpoint must be a valid https URL, got: {endpoint}\")\nclient = _get_search_client(endpoint, collection_name, credential)","typeGuard":"from urllib.parse import urlparse\n\n\ndef is_valid_search_endpoint(endpoint: str | None) -> bool:\n    if not isinstance(endpoint, str):\n        return False\n    p = urlparse(endpoint)\n    return p.scheme in (\"http\", \"https\") and bool(p.netloc)","tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreInitializationException\n\ntry:\n    client = _get_search_client(endpoint, collection_name, credential)\nexcept VectorStoreInitializationException as e:\n    cause = e.__cause__\n    raise RuntimeError(f\"SearchClient construction failed: {cause}\") from e","preventionTips":["Validate the endpoint is a well-formed https URL before constructing","Ensure the credential type matches the endpoint (key vs token)","Align the azure-search-documents version with the kwargs you pass"],"tags":["azure","azure-ai-search","vector-store","configuration","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}