{"record":{"id":"4bb18316a0917688","repo":"microsoft/semantic-kernel","slug":"collection-name-can-not-be-empty","errorCode":null,"errorMessage":"Collection name can not be empty.","messagePattern":"Collection name can not be empty\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py","lineNumber":197,"sourceCode":"\n        Args:\n            collection_name (str): Name of the collection. Case-insensitive.\n                Must have name that is valid file name for the current OS environment.\n            ndim (int, optional): Number of dimensions. Defaults to 0.\n            metric (Union[str, MetricKind, CompiledMetric], optional): Metric kind. Defaults to MetricKind.IP.\n            dtype (Optional[Union[str, ScalarKind]], optional): Data type. Defaults to None.\n            connectivity (int, optional): Connectivity parameter. Defaults to None.\n            expansion_add (int, optional): Expansion add parameter. Defaults to None.\n            expansion_search (int, optional): Expansion search parameter. Defaults to None.\n            view (bool, optional): Viewing flag. Defaults to False.\n\n        Raises:\n            ValueError: If collection with the given name already exists.\n            ValueError: If collection name is empty string.\n        \"\"\"\n        collection_name = collection_name.lower()\n        if not collection_name:\n            raise ServiceInvalidRequestError(\"Collection name can not be empty.\")\n        if collection_name in self._collections:\n            raise ServiceInvalidRequestError(f\"Collection with name {collection_name} already exists.\")\n\n        embeddings_index_path = (\n            self._get_collection_path(collection_name, file_type=_CollectionFileType.USEARCH)\n            if self._persist_directory\n            else None\n        )\n\n        embeddings_index = Index(\n            ndim=ndim,\n            metric=metric,\n            dtype=dtype,\n            connectivity=connectivity,\n            expansion_add=expansion_add,\n            expansion_search=expansion_search,\n            path=embeddings_index_path,\n            view=view,","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py#L179-L215","documentation":"Raised by USearchMemoryStore.create_collection (ServiceInvalidRequestError, a ServiceResponseException subclass) when `collection_name.lower()` is an empty string. The store validates the name after lowercasing and before registering the collection, so an empty name is rejected up front rather than producing a corrupt in-memory entry.","triggerScenarios":"Calling `await store.create_collection('')` (or a variable that resolves to an empty string). Note: passing None fails earlier with AttributeError on `.lower()`, so this specifically guards empty strings.","commonSituations":"Collection name read from config/env that is unset and defaults to ''; whitespace-only names are NOT caught here (they pass the `not` check only if they strip to empty — they do not, since ' '.lower() is truthy); upstream code that builds names dynamically yielding ''.","solutions":["Provide a non-empty collection name: `await store.create_collection('my_docs')`.","Validate/strip the name before calling: `name = name.strip(); assert name`.","Fix the config or env source that yields an empty collection name."],"exampleFix":"// before\nawait store.create_collection(cfg.get('collection', ''))\n// after\nname = (cfg.get('collection') or '').strip()\nif not name:\n    raise ValueError('collection name required')\nawait store.create_collection(name)","handlingStrategy":"validation","validationCode":"name = (collection_name or '').strip().lower()\nif not name:\n    raise ValueError('collection name must not be empty')\nawait store.create_collection(name)","typeGuard":"def is_valid_collection_name(name: str | None) -> bool:\n    return bool(name) and isinstance(name, str) and name.strip() != ''","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidRequestError\ntry:\n    await store.create_collection(name)\nexcept ServiceInvalidRequestError as e:\n    if 'empty' in str(e):\n        name = fallback_name\n        await store.create_collection(name)\n    else:\n        raise","preventionTips":["Strip and assert collection names at the config/source boundary.","Never derive names from optional config without a non-empty default.","Add a unit test that empty names are rejected before reaching the store."],"tags":["usearch","memory-store","validation","invalid-request"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}