chromadb InvalidCollectionException: collection does not exist
Fixes ChromaDB InvalidCollectionException when the named collection doesnt exist. Use when get_collection fails, when an agent queries before creating the collection, or when the persist directory points at the wrong path. Not for dimension mismatches, for auth errors, or for corrupted persistence.
TL;DR
get_collection throws InvalidCollectionException because no collection with that name exists in the ChromaDB instance you connected to. Fix it by creating the collection first (or using getorcreate_collection), and double-check the persist path and client mode so you arent talking to a fresh empty database.
chromadb InvalidCollectionException: collection does not existUse this when
client.get_collection("name")raises InvalidCollectionException- An agent queries a collection it never created
- The error appears after changing persist directories or client modes
Not for this skill when
- The collection exists but inserts fail on dimensions (thats an embedding mismatch)
- The client cant connect at all (thats the server or path)
- Persistence files look corrupted (thats a recovery job)
Steps
- List what actually exists in the instance you connected to:
print([c.name for c in client.list_collections()])Expected output: the real collection names. If your name isnt there, the bug is confirmed; check for typos and case differences.
- Create it if it should exist, or switch to get-or-create:
collection = client.get_or_create_collection("docs")Expected output: no exception. get_collection is strict by design; get_or_create_collection is what most pipelines actually want.
- Verify the persist path. A common trap is creating the collection under one path and reading from another:
import chromadb
client = chromadb.PersistentClient(path="/data/chroma")
print([c.name for c in client.list_collections()])Expected output: the collections you expect. If the list is empty, the path is wrong or the data was written by an in-memory client that never persisted.
- Check client mode consistency: an HttpClient and a PersistentClient are separate stores that share nothing:
# pick ONE mode everywhere in the pipelineExpected output: all pipeline stages use the same client construction. Mixing modes is the same as using two different databases.
Variant phrasings
collection exists in one script but not another
The two scripts use different persist paths or different client modes. Print the path in both.
worked yesterday, gone today
The persist directory was wiped (ephemeral container storage) or the path is relative and the working dir changed. Use absolute paths.
Why it happens
ChromaDB collections live inside a specific database instance (a path, a server, or memory). get_collection does a strict lookup and throws when the name is absent, which happens through typos, wrong paths, mixed client modes, or simply querying before any write. Agents hit it because they generate the query code and the ingest code in separate steps that disagree on the name or path.
Edge cases
- Collection names are case-sensitive; "Docs" and "docs" are different collections.
- Deleting the persist directory while a client holds it open produces confusing states; restart the client after filesystem changes.
- In client/server mode, the server's data dir is what matters, not the client's local path.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_ItI7uXjP539VVDKjU0Mjtw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.