{"record":{"id":"99b6d8b07088f5c2","repo":"microsoft/semantic-kernel","slug":"error-self-search-index-client-not-set-1","errorCode":null,"errorMessage":"Error: self._search_index_client not set 1.","messagePattern":"Error: self\\._search_index_client not set 1\\.","errorType":"exception","errorClass":"MemoryConnectorInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/azure_cognitive_search_memory_store.py","lineNumber":154,"sourceCode":"            )\n            vector_search = VectorSearch(\n                profiles=[vector_search_profile],\n                algorithms=[\n                    HnswAlgorithmConfiguration(\n                        name=vector_search_algorithm_name,\n                        kind=\"hnsw\",\n                        parameters=HnswParameters(\n                            m=4,  # Number of bidirectional links, typically between 4 and 10\n                            ef_construction=400,  # Size during indexing, range: 100-1000\n                            ef_search=500,  # Size during search, range: 100-1000\n                            metric=\"cosine\",  # Can be \"cosine\", \"dotProduct\", or \"euclidean_distance\"\n                        ),\n                    )\n                ],\n            )\n\n        if not self._search_index_client:\n            raise MemoryConnectorInitializationError(\"Error: self._search_index_client not set 1.\")\n\n        # Check to see if collection exists\n        collection_index = None\n        with contextlib.suppress(ResourceNotFoundError):\n            collection_index = await self._search_index_client.get_index(collection_name.lower())\n\n        if not collection_index:\n            # Create the search index with the semantic settings\n            index = SearchIndex(\n                name=collection_name.lower(),\n                fields=get_index_schema(self._vector_size, vector_search_profile_name),\n                vector_search=vector_search,\n                encryption_key=search_resource_encryption_key,\n            )\n\n            await self._search_index_client.create_index(index)\n\n    async def get_collections(self) -> list[str]:","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/azure_cognitive_search_memory_store.py#L136-L172","documentation":"Defensive guard inside `AzureCognitiveSearchMemoryStore.create_collection` (and the index-creation flow): after assembling the vector search config, it asserts `self._search_index_client` is set and otherwise raises `MemoryConnectorInitializationError`. The client is normally assigned in `__init__` via `get_search_index_async_client`, so reaching this error implies the store was not properly initialized (client construction silently failed or the object was partially built).","triggerScenarios":"Calling `create_collection` on a store whose `_search_index_client` is None — e.g. the constructor completed without assigning the client, the object was instantiated in a way that bypassed `__init__`, or a prior failure left the store in a half-initialized state. Given current code this is largely a sanity check.","commonSituations":"Mocking/instantiating the store for tests without going through `__init__`; a code path where `get_search_index_async_client` returned None and was assigned as-is (current constructor would have raised earlier in `utils.py`, so this guards against regressions); subclass overriding `__init__` and forgetting the client.","solutions":["Always construct the store via its `__init__` so `_search_index_client` is populated from `get_search_index_async_client`.","If subclassing, ensure `super().__init__(...)` runs and sets the client.","Before calling `create_collection`, assert `store._search_index_client is not None` to fail earlier with context.","Ensure the constructor's settings/credentials are valid so client construction doesn't yield None."],"exampleFix":"// before\nstore = AzureCognitiveSearchMemoryStore.__new__(AzureCognitiveSearchMemoryStore)\nawait store.create_collection(\"idx\")  # client is None\n\n// after\nstore = AzureCognitiveSearchMemoryStore(\n    search_endpoint=os.environ[\"AZURE_COGNITIVE_SEARCH_ENDPOINT\"],\n    admin_key=os.environ[\"AZURE_COGNITIVE_SEARCH_ADMIN_KEY\"],\n    vector_size=1536,\n)\nawait store.create_collection(\"idx\")","handlingStrategy":"type-guard","validationCode":"def store_has_client(store) -> bool:\n    return getattr(store, \"_search_index_client\", None) is not None\n\n# assert store_has_client(store) before store.create_collection(...)","typeGuard":"def is_initialized_acs_store(store) -> bool:\n    return (\n        store is not None\n        and hasattr(store, \"_search_index_client\")\n        and store._search_index_client is not None\n    )","tryCatchPattern":"from semantic_kernel.exceptions import MemoryConnectorInitializationError\ntry:\n    await store.create_collection(\"idx\")\nexcept MemoryConnectorInitializationError as e:\n    if \"_search_index_client not set\" in str(e):\n        raise RuntimeError(\"store not initialized; rebuild via constructor\") from e\n    raise","preventionTips":["Always build the store through its `__init__` (with valid settings) so the client is set.","If subclassing, call `super().__init__(...)` to preserve client assignment.","Assert `_search_index_client is not None` right after construction to fail fast."],"tags":["azure-cognitive-search","initialization","defensive-guard","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}