{"record":{"id":"b6ed7e5b74c57934","repo":"chroma-core/chroma","slug":"config-is-missing-a-required-field","errorCode":null,"errorMessage":"Config is missing a required field","messagePattern":"Config is missing a required field","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts","lineNumber":196,"sourceCode":"        throw new Error(`Error calling Chroma Embedding API: ${error}`);\n      }\n    }\n  }\n\n  public defaultSpace(): EmbeddingFunctionSpace {\n    return \"cosine\";\n  }\n\n  public supportedSpaces(): EmbeddingFunctionSpace[] {\n    return [\"cosine\", \"l2\", \"ip\"];\n  }\n\n  public static buildFromConfig(\n    config: ChromaCloudQwenConfig,\n    client?: ChromaClient,\n  ): ChromaCloudQwenEmbeddingFunction {\n    if (config.model === undefined || config.task === undefined) {\n      throw new ChromaValueError(\"Config is missing a required field\");\n    }\n\n    // Deserialize instructions dict from string keys to enum keys (if needed)\n    // The config.instructions will have string keys like \"nl_to_code\" and \"documents\"\n    // We need to convert these to the enum values for proper runtime usage\n    let deserializedInstructions: ChromaCloudQwenEmbeddingInstructions;\n\n    if (config.instructions) {\n      deserializedInstructions = {} as ChromaCloudQwenEmbeddingInstructions;\n      for (const [taskKey, targets] of Object.entries(config.instructions)) {\n        deserializedInstructions[taskKey] = {} as Record<\n          ChromaCloudQwenEmbeddingTarget,\n          string\n        >;\n        for (const [targetKey, instruction] of Object.entries(targets)) {\n          // targetKey is the enum value string like \"documents\" or \"query\"\n          const targetEnum = targetKey as ChromaCloudQwenEmbeddingTarget;\n          deserializedInstructions[taskKey][targetEnum] = instruction;","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts#L178-L214","documentation":"Thrown by the static buildFromConfig() of ChromaCloudQwenEmbeddingFunction with a ChromaValueError when the config object being deserialized lacks model or task. Chroma stores embedding-function configs and rebuilds functions from them (e.g., when a collection is re-opened); those two fields are required to reconstruct the Qwen function, so their absence is a config corruption or schema drift signal.","triggerScenarios":"Passing a hand-built config to buildFromConfig({ config }) with only api_key_env_var or instructions; loading a persisted collection whose stored EF config was written by an older library version without model/task; YAML/JSON config file missing the fields.","commonSituations":"Migrating between chromadb JS versions where the config schema changed; manually crafting EF configs instead of using getConfig() from a live instance; truncated config stores.","solutions":["Include both required fields: config.model (a ChromaCloudQwenEmbeddingModel value) and config.task (string or null).","Build configs from a live instance: new ChromaCloudQwenEmbeddingFunction(...).getConfig() round-trips every required field.","If loading stored configs from an older version, backfill model/task before calling buildFromConfig."],"exampleFix":"// before\nconst ef = ChromaCloudQwenEmbeddingFunction.buildFromConfig({\n  api_key_env_var: \"CHROMA_API_KEY\",\n}); // no model/task\n\n// after\nconst ef = ChromaCloudQwenEmbeddingFunction.buildFromConfig({\n  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n  task: null,\n  api_key_env_var: \"CHROMA_API_KEY\",\n});","handlingStrategy":"validation","validationCode":"function isCompleteQwenConfig(c: Partial<ChromaCloudQwenConfig>): c is ChromaCloudQwenConfig {\n  return c.model !== undefined && c.task !== undefined;\n}\n\nif (!isCompleteQwenConfig(storedConfig)) {\n  throw new Error(\"Stored Qwen config is missing model or task; backfill before rebuild\");\n}\nconst ef = ChromaCloudQwenEmbeddingFunction.buildFromConfig(storedConfig);","typeGuard":"function isCompleteQwenConfig(c: unknown): c is ChromaCloudQwenConfig {\n  if (typeof c !== \"object\" || c === null) return false;\n  const cfg = c as Record<string, unknown>;\n  return typeof cfg.model === \"string\" && (cfg.task === null || typeof cfg.task === \"string\");\n}","tryCatchPattern":null,"preventionTips":["Persist configs via getConfig() so all required fields are captured.","Validate stored configs after library upgrades before rebuilding functions.","Add schema checks (model, task present) when loading configs from YAML/JSON."],"tags":["config","validation","qwen","embeddings","deserialization"],"backgroundTag":"missing-required-config-field","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}