{"record":{"id":"22656323a068ef66","repo":"chroma-core/chroma","slug":"collection-name-does-not-exist","errorCode":null,"errorMessage":"Collection {name} does not exist.","messagePattern":"Collection (.+?) does not exist\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/segment.py","lineNumber":505,"sourceCode":"    @override\n    @rate_limit\n    def delete_collection(\n        self,\n        name: str,\n        tenant: str = DEFAULT_TENANT,\n        database: str = DEFAULT_DATABASE,\n    ) -> None:\n        existing = self._sysdb.get_collections(\n            name=name, tenant=tenant, database=database\n        )\n\n        if existing:\n            self._manager.delete_segments(existing[0].id)\n            self._sysdb.delete_collection(\n                existing[0].id, tenant=tenant, database=database\n            )\n        else:\n            raise ValueError(f\"Collection {name} does not exist.\")\n\n    @trace_method(\"SegmentAPI._add\", OpenTelemetryGranularity.OPERATION)\n    @override\n    @rate_limit\n    def _add(\n        self,\n        ids: IDs,\n        collection_id: UUID,\n        embeddings: Embeddings,\n        metadatas: Optional[Metadatas] = None,\n        documents: Optional[Documents] = None,\n        uris: Optional[URIs] = None,\n        tenant: str = DEFAULT_TENANT,\n        database: str = DEFAULT_DATABASE,\n    ) -> bool:\n        coll = self._get_collection(collection_id)\n        self._manager.hint_use_collection(collection_id, t.Operation.ADD)\n        validate_batch(","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/segment.py#L487-L523","documentation":"SegmentAPI.delete_collection resolves the collection by name in the system database before removing its segments and metadata; when nothing matches that name in the given tenant/database, it raises ValueError('Collection {name} does not exist.'). This is embedded mode's plain-ValueError form of a not-found delete; over HTTP the same situation surfaces as a typed 404 NotFoundError.","triggerScenarios":"client.delete_collection('name') where no collection with that name exists in the tenant/database — double deletes, deleting after another client/process already removed it, or a misspelled name.","commonSituations":"Idempotent startup/teardown code that deletes a known collection; test cleanup running twice; being connected to a different persist directory, tenant or database than where the collection lives; name casing or whitespace mismatches.","solutions":["Check existence first with client.list_collections() and only delete when present","Catch the ValueError and treat 'does not exist' as success when the delete is meant to be idempotent","Verify tenant/database (and persist path) match where the collection was created"],"exampleFix":"// before\nclient.delete_collection('docs')  # ValueError if missing\n\n// after\nnames = [c.name for c in client.list_collections()]\nif 'docs' in names:\n    client.delete_collection('docs')","handlingStrategy":"validation","validationCode":"def collection_exists(client, name: str, tenant=None, database=None) -> bool:\n    return any(c.name == name for c in client.list_collections())\n\ndef delete_collection_idempotent(client, name: str) -> None:\n    if collection_exists(client, name):\n        client.delete_collection(name)","typeGuard":null,"tryCatchPattern":"try:\n    client.delete_collection('docs')\nexcept ValueError as e:\n    if 'does not exist' not in str(e):\n        raise  # a different ValueError — re-raise","preventionTips":["Wrap deletes in an existence check or an idempotent helper","Confirm tenant/database and persist path before deleting","In tests, use unique collection names per test instead of delete-recreate races"],"tags":["chroma","delete-collection","not-found","value-error"],"backgroundTag":"delete-nonexistent-resource","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}