High severity beginner · Fix: 2-5 min

ValueError

chromadb.errors.ValueError

What this error means
This error occurs when attempting to create a ChromaDB collection with a name that already exists in the database.

Stack trace

traceback
ValueError: Collection with name 'my_collection' already exists.
  File "app.py", line 42, in create_collection
    collection = client.create_collection(name="my_collection")
  File "chromadb/client.py", line 120, in create_collection
    raise ValueError(f"Collection with name '{name}' already exists.")
QUICK FIX
Check for existing collections with client.list_collections() before creating a new one to avoid this error.

Why it happens

ChromaDB enforces unique collection names to prevent data conflicts. When your code tries to create a collection with a name that is already registered, it raises this ValueError to avoid overwriting or duplicating collections.

Detection

Before creating a collection, check if the collection name already exists by querying the client.list_collections() method and handle the existence case gracefully.

Causes & fixes

1

Code attempts to create a collection without checking if it already exists

✓ Fix

Use client.list_collections() to check for existing collections before calling create_collection()

2

Multiple parts of the code or concurrent processes try to create the same collection simultaneously

✓ Fix

Implement synchronization or locking to ensure only one creation attempt occurs, or catch the ValueError and handle it by retrieving the existing collection

3

Re-running initialization scripts without cleanup causes repeated create_collection calls

✓ Fix

Add logic to reuse existing collections or delete collections before re-creating them during development

Code: broken vs fixed

Broken - triggers the error
python
from chromadb import Client

client = Client()

# This line raises ValueError if collection exists
collection = client.create_collection(name="my_collection")
Fixed - works correctly
python
import os
from chromadb import Client

client = Client()

existing_collections = [col.name for col in client.list_collections()]
if "my_collection" in existing_collections:
    collection = client.get_collection(name="my_collection")  # Reuse existing collection
else:
    collection = client.create_collection(name="my_collection")  # Create new collection

print(f"Using collection: {collection.name}")  # Confirm success
Added a check for existing collections before creating a new one to prevent the ValueError from duplicate collection creation.
⚠

Workaround

Wrap create_collection in try/except ValueError, and if caught, call get_collection to retrieve the existing collection instead of failing.

✓

Prevention

Design your application to query existing collections before creation and handle concurrency with locks or retries to avoid duplicate collection creation attempts.

Python 3.9+ · chromadb >=0.3.0 · tested on 0.4.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.