{"record":{"id":"3e7eac14f3ebb114","repo":"microsoft/semantic-kernel","slug":"collection-with-name-collection-name-already-exi","errorCode":null,"errorMessage":"Collection with name {collection_name} already exists.","messagePattern":"Collection with name (.+?) already exists\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py","lineNumber":199,"sourceCode":"            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,\n        )\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py#L181-L217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait store.create_collection('docs')\n// after\nif not await store.does_collection_exist('docs'):\n    await store.create_collection('docs')","handlingStrategy":"validation","validationCode":"name = collection_name.lower()\nif not await store.does_collection_exist(name):\n    await store.create_collection(name)\nelse:\n    logger.info('collection %s already exists; skipping create', name)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidRequestError\ntry:\n    await store.create_collection(name)\nexcept ServiceInvalidRequestError as e:\n    if 'already exists' in str(e):\n        pass  # idempotent create\n    else:\n        raise","preventionTips":["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."],"tags":["usearch","memory-store","duplicate","invalid-request","case-insensitive"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}