microsoft/semantic-kernel · error · MemoryConnectorInitializationError

Error: self._search_index_client not set 1.

Error message

Error: self._search_index_client not set 1.

What it means

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).

Source

Thrown at python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/azure_cognitive_search_memory_store.py:154

            )
            vector_search = VectorSearch(
                profiles=[vector_search_profile],
                algorithms=[
                    HnswAlgorithmConfiguration(
                        name=vector_search_algorithm_name,
                        kind="hnsw",
                        parameters=HnswParameters(
                            m=4,  # Number of bidirectional links, typically between 4 and 10
                            ef_construction=400,  # Size during indexing, range: 100-1000
                            ef_search=500,  # Size during search, range: 100-1000
                            metric="cosine",  # Can be "cosine", "dotProduct", or "euclidean_distance"
                        ),
                    )
                ],
            )

        if not self._search_index_client:
            raise MemoryConnectorInitializationError("Error: self._search_index_client not set 1.")

        # Check to see if collection exists
        collection_index = None
        with contextlib.suppress(ResourceNotFoundError):
            collection_index = await self._search_index_client.get_index(collection_name.lower())

        if not collection_index:
            # Create the search index with the semantic settings
            index = SearchIndex(
                name=collection_name.lower(),
                fields=get_index_schema(self._vector_size, vector_search_profile_name),
                vector_search=vector_search,
                encryption_key=search_resource_encryption_key,
            )

            await self._search_index_client.create_index(index)

    async def get_collections(self) -> list[str]:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Always construct the store via its `__init__` so `_search_index_client` is populated from `get_search_index_async_client`.
  2. If subclassing, ensure `super().__init__(...)` runs and sets the client.
  3. Before calling `create_collection`, assert `store._search_index_client is not None` to fail earlier with context.
  4. Ensure the constructor's settings/credentials are valid so client construction doesn't yield None.

Example fix

// before
store = AzureCognitiveSearchMemoryStore.__new__(AzureCognitiveSearchMemoryStore)
await store.create_collection("idx")  # client is None

// after
store = AzureCognitiveSearchMemoryStore(
    search_endpoint=os.environ["AZURE_COGNITIVE_SEARCH_ENDPOINT"],
    admin_key=os.environ["AZURE_COGNITIVE_SEARCH_ADMIN_KEY"],
    vector_size=1536,
)
await store.create_collection("idx")
Defensive patterns

Strategy: type-guard

Validate before calling

def store_has_client(store) -> bool:
    return getattr(store, "_search_index_client", None) is not None

# assert store_has_client(store) before store.create_collection(...)

Type guard

def is_initialized_acs_store(store) -> bool:
    return (
        store is not None
        and hasattr(store, "_search_index_client")
        and store._search_index_client is not None
    )

Try / catch

from semantic_kernel.exceptions import MemoryConnectorInitializationError
try:
    await store.create_collection("idx")
except MemoryConnectorInitializationError as e:
    if "_search_index_client not set" in str(e):
        raise RuntimeError("store not initialized; rebuild via constructor") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/99b6d8b07088f5c2. Report an issue: GitHub.