{"record":{"id":"385f3125a5458847","repo":"chroma-core/chroma","slug":"the-task-type-cannot-be-changed-after-initializati","errorCode":null,"errorMessage":"The task type cannot be changed after initialization.","messagePattern":"The task type cannot be changed after initialization\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts","lineNumber":125,"sourceCode":"\n  getConfig(): StoredConfig {\n    return {\n      api_key_env_var: this.api_key_env_var,\n      model_name: this.model,\n      task_type: this.taskType,\n    };\n  }\n\n  validateConfigUpdate(\n    oldConfig: Record<string, any>,\n    newConfig: Record<string, any>,\n  ): void {\n    if (oldConfig.model_name !== newConfig.model_name) {\n      throw new Error(\"The model name cannot be changed after initialization.\");\n    }\n\n    if (oldConfig.taskType !== newConfig.taskType) {\n      throw new Error(\"The task type cannot be changed after initialization.\");\n    }\n  }\n\n  validateConfig(config: Record<string, any>): void {\n    validateConfigSchema(config, \"google_generative_ai\");\n  }\n}\n","sourceCodeStart":107,"sourceCodeEnd":133,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts#L107-L133","documentation":"Intended to block changing the Gemini taskType (RETRIEVAL_DOCUMENT vs RETREVAL_QUERY etc.) after initialization, for the same reason as the model lock: task type shapes the vectors. Caveat grounded in the source: it compares oldConfig.taskType/newConfig.taskType (camelCase) while getConfig() emits task_type (snake_case), so for configs round-tripped through getConfig() both sides are undefined and this error can never fire; it only triggers when callers supply records carrying a literal camelCase taskType key.","triggerScenarios":"validateConfigUpdate() invoked with old/new records that both contain a camelCase taskType key with different values — e.g. a wrapper that camelCases config keys before calling update, or hand-built config objects.","commonSituations":"Wrapper layers normalizing snake_case API config into camelCase; example code constructing config objects manually; otherwise usually seen as a silent no-op with getConfig()-produced configs, which is itself a bug worth reporting.","solutions":["Keep the task type identical across updates — fetch the stored config and reuse the field","Create a new collection if the task type genuinely must change","Library-level fix: compare oldConfig.task_type !== newConfig.task_type so the guard matches the keys getConfig() actually emits"],"exampleFix":"// before (library code): key never matches getConfig() output\nif (oldConfig.taskType !== newConfig.taskType) {\n  throw new Error(\"The task type cannot be changed after initialization.\");\n}\n\n// after: compare the key the config actually stores\nif (oldConfig.task_type !== newConfig.task_type) {\n  throw new Error(\"The task type cannot be changed after initialization.\");\n}","handlingStrategy":"validation","validationCode":"function taskTypeOf(cfg: Record<string, any>): unknown {\n  return cfg.taskType ?? cfg.task_type; // cover both spellings: the guard reads camelCase, getConfig() emits snake_case\n}\nfunction assertSameTaskType(oldCfg: Record<string, any>, newCfg: Record<string, any>): void {\n  if (taskTypeOf(oldCfg) !== taskTypeOf(newCfg)) {\n    throw new Error(\"task type is immutable; create a new collection instead\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await applyConfigUpdate(collection, newCfg);\n} catch (e) {\n  if (e instanceof Error && /task type cannot be changed/i.test(e.message)) {\n    // task type differs: create a new collection; retrying will not help\n  }\n  throw e;\n}","preventionTips":["Normalize config keys to snake_case before comparing or updating — the library's own guard checks mismatched key spellings","Treat task type like the model: fixed per collection, changed only via new collection","Report the taskType/task_type key mismatch upstream so the guard actually fires"],"tags":["embeddings","config","google","immutable","validation","key-mismatch"],"backgroundTag":"config-update-not-allowed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}