microsoft/semantic-kernel · error · ServiceInvalidRequestError
Collection with name {collection_name} already exists.
Error message
Collection with name {collection_name} already exists. What it means
Raised by USearchMemoryStore.create_collection (ServiceInvalidRequestError) when a collection with the given name (after lowercasing) already exists in `self._collections`. The store keys collections by lowercased name, so it treats names case-insensitively and refuses to silently overwrite an existing in-memory index.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:199
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
- Check `collection_name.lower() not in store._collections` (or call does_collection_exist) before creating.
- Delete the existing collection first if you intend to recreate it.
- If collections are loaded from disk at startup, skip create_collection for names already present.
Example fix
// before
await store.create_collection('docs')
// after
if not await store.does_collection_exist('docs'):
await store.create_collection('docs') Defensive patterns
Strategy: validation
Validate before calling
name = collection_name.lower()
if not await store.does_collection_exist(name):
await store.create_collection(name)
else:
logger.info('collection %s already exists; skipping create', name) Try / catch
from semantic_kernel.exceptions import ServiceInvalidRequestError
try:
await store.create_collection(name)
except ServiceInvalidRequestError as e:
if 'already exists' in str(e):
pass # idempotent create
else:
raise Prevention
- Make create_collection idempotent in your setup code (check existence first).
- Remember names are matched case-insensitively (lowercased).
- If collections load from disk at startup, skip recreating names already present.
When it happens
Trigger: Calling `create_collection('Docs')` when 'docs' is already present (loaded from disk at construction, or created earlier in the same process). The name is lowercased before the duplicate check.
Common situations: Re-running an app that re-creates collections on each startup without deleting first; collections auto-loaded from persist_directory that collide with names the app then tries to create; case-variant names ('Docs' vs 'docs') treated as the same.
Related errors
- Collection name can not be empty.
- Path of persist directory is not set
- Expected {expected_storage_files} files for collection {coll
- Collection {collection_name} does not exist, cannot insert.
- Key '{key}' not found in collection '{collection_name}'
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/3e7eac14f3ebb114.
Report an issue: GitHub.