{"record":{"id":"7867ae0d9ee6cbd7","repo":"microsoft/semantic-kernel","slug":"collection-name-is-required-to-create-a-search-cli","errorCode":null,"errorMessage":"Collection name is required to create a search client.","messagePattern":"Collection name is required to create a search client\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":159,"sourceCode":"    - index_name: str - Azure AI Search index name (Env var AZURE_AI_SEARCH_INDEX_NAME)\n    \"\"\"\n\n    env_prefix: ClassVar[str] = \"AZURE_AI_SEARCH_\"\n\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}).","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L141-L177","documentation":"Raised by the Azure AI Search helper _get_search_client when collection_name is falsy. The function requires a concrete collection (index) name to construct a SearchClient; if collection_name is None or an empty string it throws VectorStoreInitializationException (subclass of VectorStoreException, not ServiceException).","triggerScenarios":"Calling _get_search_client (directly, or via AzureAISearchCollection which passes collection_name) with collection_name=None or ''. This happens when a collection was created without a name or the name resolved from a model/definition was empty.","commonSituations":"Creating an AzureAISearchCollection without specifying collection_name and the inferred name (from _get_collection_name_from_model) returned None; the AZURE_AI_SEARCH_INDEX_NAME env var is unset and no explicit name was passed; a record model without a __kernel_collection_name__ attribute.","solutions":["Pass an explicit collection name: AzureAISearchCollection(collection_name='my-index', ...)","Set the AZURE_AI_SEARCH_INDEX_NAME environment variable","If inferring from a model, ensure the model class defines a collection name attribute used by _get_collection_name_from_model"],"exampleFix":"# before\ncollection = AzureAISearchCollection(\n    collection_name=None, settings=settings\n)\n\n# after\ncollection = AzureAISearchCollection(\n    collection_name=\"my-docs-index\", settings=settings\n)","handlingStrategy":"validation","validationCode":"if not collection_name:\n    raise ValueError(\"collection_name is required for an Azure AI Search client\")\nclient = _get_search_client(endpoint, collection_name, credential)","typeGuard":"def is_valid_collection_name(name: str | None) -> bool:\n    return isinstance(name, str) and name.strip() != \"\"","tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreInitializationException\n\ntry:\n    collection = AzureAISearchCollection(collection_name=name, settings=settings)\nexcept VectorStoreInitializationException as e:\n    if \"Collection name is required\" in str(e):\n        raise ValueError(\"Provide a non-empty collection_name\") from e\n    raise","preventionTips":["Always pass an explicit collection_name to AzureAISearchCollection","Set AZURE_AI_SEARCH_INDEX_NAME in your .env as a fallback","Ensure record models expose a resolvable collection name"],"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"}