microsoft/semantic-kernel · error · ServiceInvalidRequestError
Collection name can not be empty.
Error message
Collection name can not be empty.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:197
Args:
collection_name (str): Name of the collection. Case-insensitive.
Must have name that is valid file name for the current OS environment.
ndim (int, optional): Number of dimensions. Defaults to 0.
metric (Union[str, MetricKind, CompiledMetric], optional): Metric kind. Defaults to MetricKind.IP.
dtype (Optional[Union[str, ScalarKind]], optional): Data type. Defaults to None.
connectivity (int, optional): Connectivity parameter. Defaults to None.
expansion_add (int, optional): Expansion add parameter. Defaults to None.
expansion_search (int, optional): Expansion search parameter. Defaults to None.
view (bool, optional): Viewing flag. Defaults to False.
Raises:
ValueError: If collection with the given name already exists.
ValueError: If collection name is empty string.
"""
collection_name = collection_name.lower()
if not collection_name:
raise ServiceInvalidRequestError("Collection name can not be empty.")
if collection_name in self._collections:
raise ServiceInvalidRequestError(f"Collection with name {collection_name} already exists.")
embeddings_index_path = (
self._get_collection_path(collection_name, file_type=_CollectionFileType.USEARCH)
if self._persist_directory
else None
)
embeddings_index = Index(
ndim=ndim,
metric=metric,
dtype=dtype,
connectivity=connectivity,
expansion_add=expansion_add,
expansion_search=expansion_search,
path=embeddings_index_path,
view=view,View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
await store.create_collection(cfg.get('collection', ''))
// after
name = (cfg.get('collection') or '').strip()
if not name:
raise ValueError('collection name required')
await store.create_collection(name) Defensive patterns
Strategy: validation
Validate before calling
name = (collection_name or '').strip().lower()
if not name:
raise ValueError('collection name must not be empty')
await store.create_collection(name) Type guard
def is_valid_collection_name(name: str | None) -> bool:
return bool(name) and isinstance(name, str) and name.strip() != '' Try / catch
from semantic_kernel.exceptions import ServiceInvalidRequestError
try:
await store.create_collection(name)
except ServiceInvalidRequestError as e:
if 'empty' in str(e):
name = fallback_name
await store.create_collection(name)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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 ''.
Related errors
- Collection with name {collection_name} already exists.
- Limit must be less than or equal to {MAX_QUERY_WITHOUT_METAD
- Path of persist directory is not set
- Expected {expected_storage_files} files for collection {coll
- Collection {collection_name} does not exist, cannot insert.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/4bb18316a0917688.
Report an issue: GitHub.