{"record":{"id":"9b0158d722d7b5d3","repo":"chroma-core/chroma","slug":"tenant-and-database-must-be-set-on-the-client-befo","errorCode":null,"errorMessage":"tenant and database must be set on the client before calling collection(). Provide them in the ChromaClient constructor or use getCollection() instead.","messagePattern":"tenant and database must be set on the client before calling collection\\(\\)\\. Provide them in the ChromaClient constructor or use getCollection\\(\\) instead\\.","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/chroma-client.ts","lineNumber":585,"sourceCode":"      embeddingFunction: resolvedEmbeddingFunction,\n      id: data.id,\n      schema: serverSchema,\n    });\n  }\n\n  /**\n   * Returns a lightweight collection handle for the given collection ID.\n   * The handle supports operations that don't require an embedding function\n   * or schema (e.g., add with pre-computed embeddings, get, delete, count, search).\n   * Operations that require an embedding function will throw a clear error\n   * directing you to use {@link getCollection} instead.\n   * @param id - The collection ID\n   * @returns A Collection handle for the given ID\n   * @throws ChromaValueError if tenant or database are not set on the client\n   */\n  public collection(id: string): Collection {\n    if (!this._tenant || !this._database) {\n      throw new ChromaValueError(\n        \"tenant and database must be set on the client before calling collection(). \" +\n          \"Provide them in the ChromaClient constructor or use getCollection() instead.\",\n      );\n    }\n\n    return new CollectionHandle({\n      chromaClient: this,\n      apiClient: this.apiClient,\n      id,\n      tenant: this._tenant,\n      database: this._database,\n    });\n  }\n\n  /**\n   * Deletes a collection and all its data.\n   * @param options - Deletion options\n   * @param options.name - The name of the collection to delete","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/chroma-client.ts#L567-L603","documentation":"Thrown synchronously by ChromaClient.collection(id) (chroma-client.ts:585) when either this._tenant or this._database is unset. The lightweight CollectionHandle needs tenant/database to route requests, and unlike getCollection() (which resolves them via the async _path() identity lookup), collection() is deliberately synchronous, so it requires them to already be present on the client.","triggerScenarios":"Calling client.collection(\"<uuid>\") on a client constructed without explicit tenant and database values — typically a CloudClient that relied on auto-discovery, or a ChromaClient whose tenant/database were never provided and whose _path() has not run yet.","commonSituations":"Switching code from await client.getCollection(name) to the fast sync handle API without adding tenant/database to the constructor; using an ID from another tenant; refactoring away from the async path.","solutions":["Provide tenant and database in the constructor: new ChromaClient({ tenant, database }) / new CloudClient({ apiKey, tenant, database }).","Or use await client.getCollection(name) instead, which resolves tenant/database lazily.","If you already know the values at call time, call any awaited method once (e.g. listCollections) to populate _tenant/_database, then use collection(id)."],"exampleFix":"// before\nconst client = new CloudClient({ apiKey: KEY }); // no tenant/database\nconst col = client.collection(\"col-id\"); // throws ChromaValueError\n\n// after\nconst client = new CloudClient({ apiKey: KEY, tenant: \"my-tenant\", database: \"my-db\" });\nconst col = client.collection(\"col-id\"); // synchronous lightweight handle","handlingStrategy":"validation","validationCode":"const identity = await client.getUserIdentity();\nconst ready = Boolean(identity.tenant && [...new Set(identity.databases)].length === 1);\nif (!ready) {\n  // fall back to the async API instead of the sync handle\n  const col = await client.getCollection({ name: \"docs\" });\n}","typeGuard":"const canUseSyncHandle = (c: ChromaClient): boolean =>\n  // tenant/database must already be materialized on the client\n  (c as any)._tenant != null && (c as any)._database != null; // prefer: construct with both instead","tryCatchPattern":"try {\n  const col = client.collection(id);\n} catch (e) {\n  if (e instanceof ChromaValueError && e.message.includes(\"tenant and database must be set\")) {\n    return await client.getCollection({ name }); // async path resolves them\n  }\n  throw e;\n}","preventionTips":["Construct ChromaClient/CloudClient with explicit tenant and database when you plan to use collection(id).","Treat collection(id) as an optimization available only after client configuration is complete.","Prefer getCollection() when configuration is auto-discovered."],"tags":["configuration","synchronous-api","collection-handle","validation"],"backgroundTag":"missing-required-client-config","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}