{"record":{"id":"f363e64411c8425d","repo":"chroma-core/chroma","slug":"invalid-hnsw-config-provided-in-updatecollectionco","errorCode":null,"errorMessage":"Invalid HNSW config provided in UpdateCollectionConfiguration","messagePattern":"Invalid HNSW config provided in UpdateCollectionConfiguration","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/CollectionConfiguration.ts","lineNumber":319,"sourceCode":"}\n\nexport function updateCollectionConfigurationToJson(\n  config: UpdateCollectionConfiguration,\n): Record<string, any> {\n  if (config.hnsw && config.spann) {\n    throw new InvalidConfigurationError(\n      \"Cannot specify both 'hnsw' and 'spann' configurations during update.\",\n    );\n  }\n  let hnswConfig = config.hnsw;\n  let spannConfig = config.spann;\n  let ef = config.embedding_function;\n  let efConfig: Record<string, any> | null | undefined = undefined; // Initialize as undefined\n\n  // Validate HNSW config if present\n  if (hnswConfig) {\n    if (typeof hnswConfig !== \"object\") {\n      throw new Error(\n        \"Invalid HNSW config provided in UpdateCollectionConfiguration\",\n      );\n    }\n  }\n\n  // Validate SPANN config if present\n  if (spannConfig) {\n    if (typeof spannConfig !== \"object\") {\n      throw new Error(\n        \"Invalid SPANN config provided in UpdateCollectionConfiguration\",\n      );\n    }\n  }\n\n  // Handle embedding function serialization only if explicitly provided (ef !== undefined)\n  if (ef !== undefined) {\n    efConfig = serializeEmbeddingFunction(ef);\n  }","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/CollectionConfiguration.ts#L301-L337","documentation":"updateCollectionConfigurationToJson validates the hnsw field of an UpdateCollectionConfiguration: present-but-not-an-object throws this plain Error. UpdateHNSWConfiguration is a partial object of tunables such as { space, num_neighbors, search_ef, ef_search }; null/undefined are allowed (they mean 'leave unchanged'), but strings/numbers/booleans are not.","triggerScenarios":"collection.modify({ configuration: { hnsw: 'search_ef=200' } }); hnsw: process.env.HNSW_UPDATE (unparsed string); hnsw: 10.","commonSituations":"Reading tuning parameters from env vars or feature-flag services as strings; building the update payload via template literals; misunderstanding the partial-update shape ({ hnsw: { search_ef } } rather than a query-string).","solutions":["Pass hnsw as an object with only the fields you want to change: { hnsw: { search_ef: 200 } }.","JSON.parse any stringified source before embedding it in the update payload.","Type the payload as UpdateCollectionConfiguration so the compiler catches primitive mistakes."],"exampleFix":"// before\nawait col.modify({ configuration: { hnsw: process.env.HNSW_UPDATE! } });\n\n// after\nawait col.modify({ configuration: { hnsw: { search_ef: 200 } } });","handlingStrategy":"type-guard","validationCode":"if (cfg.hnsw !== undefined && typeof cfg.hnsw !== 'object') {\n  throw new TypeError('update hnsw must be an object of HNSW tunables');\n}","typeGuard":"function isUpdateHnsw(v: unknown): v is UpdateHNSWConfiguration {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  await col.modify({ configuration });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Invalid HNSW config provided in UpdateCollectionConfiguration')) {\n    // coerce to an object: typeof x === 'string' ? JSON.parse(x) : x\n  }\n  throw e;\n}","preventionTips":["Type update payloads as UpdateCollectionConfiguration (partial fields) rather than Record<string, any>.","Parse string-sourced tunables with JSON.parse at the config boundary, once.","Unit-test your update builder with undefined/absent fields to catch accidental primitives."],"tags":["configuration","validation","hnsw","type-mismatch","update","collection-modify"],"backgroundTag":"config-type-mismatch","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}