{"record":{"id":"08a2b45ce9c32d6c","repo":"chroma-core/chroma","slug":"cannot-enable-all-index-types-globally-must-speci","errorCode":null,"errorMessage":"Cannot enable all index types globally. Must specify either config or key.","messagePattern":"Cannot enable all index types globally\\. Must specify either config or key\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/schema.ts","lineNumber":510,"sourceCode":"   * @example\n   * ```typescript\n   * const schema = new Schema();\n   * schema.setCmek(Cmek.gcp(\n   *   \"projects/my-project/locations/us-central1/keyRings/my-ring/cryptoKeys/my-key\"\n   * ));\n   * ```\n   */\n  setCmek(cmek: Cmek | null): this {\n    this.cmek = cmek;\n    return this;\n  }\n\n  createIndex(config?: IndexConfig, key?: string): this {\n    const configProvided = config !== undefined && config !== null;\n    const keyProvided = key !== undefined && key !== null;\n\n    if (!configProvided && !keyProvided) {\n      throw new Error(\n        \"Cannot enable all index types globally. Must specify either config or key.\",\n      );\n    }\n\n    // Disallow using special internal key #embedding\n    if (keyProvided && key && key === EMBEDDING_KEY) {\n      throw new Error(\n        `Cannot create index on special key '${key}'. This key is managed automatically by the system. Invoke createIndex(new VectorIndexConfig(...)) without specifying a key to configure the vector index globally.`,\n      );\n    }\n\n    // Only allow #document with FtsIndexConfig\n    if (\n      keyProvided &&\n      key === DOCUMENT_KEY &&\n      !(config instanceof FtsIndexConfig)\n    ) {\n      throw new Error(","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/schema.ts#L492-L528","documentation":"Schema.createIndex(config?, key?) requires at least one argument: a concrete IndexConfig to enable, optionally scoped to a key. Calling it with neither would mean 'turn on every index type globally', which the API deliberately rejects — you must state which index you want.","triggerScenarios":"schema.createIndex(); schema.createIndex(undefined, undefined); passing a config variable that is conditionally undefined (config = cond ? cfg : undefined) while no key is given.","commonSituations":"Optional-index migrations that call createIndex unconditionally; copying a doc example but dropping its arguments; TypeScript not flagging it because both parameters are optional.","solutions":["Pass a global config: createIndex(new VectorIndexConfig(...)) configures the collection-wide vector index.","Or pass config plus key for a scoped index, e.g. createIndex(new FtsIndexConfig(), '#document').","If the index is optional, guard the call: if (cfg) schema.createIndex(cfg)."],"exampleFix":"// before\nschema.createIndex(); // nothing specified\n\n// after\nschema.createIndex(new VectorIndexConfig()); // global vector index config","handlingStrategy":"validation","validationCode":"function createIndexSafe(schema: Schema, config: IndexConfig | null | undefined, key?: string | null): void {\n  const hasConfig = config !== undefined && config !== null;\n  const hasKey = key !== undefined && key !== null;\n  if (!hasConfig && !hasKey) {\n    throw new Error('createIndex requires an IndexConfig and/or a key');\n  }\n  schema.createIndex(config ?? undefined, key ?? undefined);\n}","typeGuard":"const hasIndexTarget = (\n  config?: IndexConfig | null,\n  key?: string | null,\n): boolean =>\n  (config !== undefined && config !== null) ||\n  (key !== undefined && key !== null);","tryCatchPattern":"try {\n  schema.createIndex(config, key);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Cannot enable all index types globally. Must specify either config or key.') {\n    // default to a global vector index and retry\n  } else {\n    throw e;\n  }\n}","preventionTips":["Wrap createIndex in your own function whose parameters make the config required.","Unit-test schema assembly so empty migration steps fail in CI, not at runtime."],"tags":["schema","index-config","chroma","typescript"],"backgroundTag":"invalid-index-configuration","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}