{"record":{"id":"3dfa2795ace2177f","repo":"microsoft/semantic-kernel","slug":"collection-collection-name-does-not-exist-canno-3dfa27","errorCode":null,"errorMessage":"Collection {collection_name} does not exist, cannot insert.","messagePattern":"Collection (.+?) does not exist, cannot insert\\.","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py","lineNumber":332,"sourceCode":"\n        Args:\n            collection_name (str): Name of the collection to search within.\n            records (List[MemoryRecord]): Records to upsert.\n            compact (bool, optional): Removes links to removed nodes (expensive). Defaults to False.\n            copy (bool, optional): Should the index store a copy of vectors. Defaults to True.\n            threads (int, optional): Optimal number of cores to use. Defaults to 0.\n            log (Union[str, bool], optional): Whether to print the progress bar. Defaults to False.\n            batch_size (int, optional): Number of vectors to process at once. Defaults to 0.\n\n        Raises:\n            KeyError: If collection not exist\n\n        Returns:\n            List[str]: List of IDs.\n        \"\"\"\n        collection_name = collection_name.lower()\n        if collection_name not in self._collections:\n            raise ServiceResourceNotFoundError(f\"Collection {collection_name} does not exist, cannot insert.\")\n\n        ucollection = self._collections[collection_name]\n        all_records_id = [record._id for record in records]\n\n        # Remove vectors from index\n        remove_labels = [\n            ucollection.embeddings_id_to_label[id] for id in all_records_id if id in ucollection.embeddings_id_to_label\n        ]\n        ucollection.embeddings_index.remove(remove_labels, compact=compact, threads=threads)\n\n        # Determine label insertion points\n        table_num_rows = ucollection.embeddings_data_table.num_rows\n        insert_labels = np.arange(table_num_rows, table_num_rows + len(records))\n\n        # Add embeddings to index\n        ucollection.embeddings_index.add(\n            keys=insert_labels,\n            vectors=np.stack([record.embedding for record in records]),","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py#L314-L350","documentation":"Raised by USearchMemoryStore.upsert_batch (ServiceResourceNotFoundError) when the target collection is not in `self._collections`. The message says 'cannot insert' because upsert first removes existing labels then adds — so a missing collection is rejected before any index mutation. The name is matched case-insensitively (lowercased).","triggerScenarios":"Calling `await store.upsert_batch('docs', records)` when 'docs' was never created in this process (and not loaded from disk). The existence check runs before removing/adding vectors.","commonSituations":"Forgot to call create_collection before upserting; collection name typo or case mismatch (names are lowercased); in-memory store where the collection was lost after a restart; persist_directory not set so nothing was loaded.","solutions":["Create the collection first: `await store.create_collection('docs', ndim=1536)`.","Guard with `if 'docs' not in ...` / does_collection_exist before upserting.","Match the name exactly (it is lowercased internally)."],"exampleFix":"// before\nawait store.upsert_batch('docs', records)\n// after\nif not await store.does_collection_exist('docs'):\n    await store.create_collection('docs', ndim=1536)\nawait store.upsert_batch('docs', records)","handlingStrategy":"validation","validationCode":"name = collection_name.lower()\nif not await store.does_collection_exist(name):\n    await store.create_collection(name, ndim=embedding_dim)\nawait store.upsert_batch(name, records)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\ntry:\n    await store.upsert_batch(name, records)\nexcept ServiceResourceNotFoundError:\n    await store.create_collection(name, ndim=dim)\n    await store.upsert_batch(name, records)","preventionTips":["Create the collection with the correct ndim before the first upsert.","Keep collection names consistent (they are lowercased internally).","If persistence is off, recreate collections on each process start."],"tags":["usearch","memory-store","collection-not-found","upsert"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}