{"record":{"id":"28bbbdf43896908d","repo":"chroma-core/chroma","slug":"expected-operand-value-to-be-an-array-for-operat","errorCode":null,"errorMessage":"Expected operand value to be an array for ${operator}, but got ${operand}","messagePattern":"Expected operand value to be an array for (.+?), but got (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":589,"sourceCode":"      if (Object.keys(value).length != 1) {\n        throw new ChromaValueError(\n          `Expected operator expression to have one operator, but got ${value}`,\n        );\n      }\n\n      const [operator, operand] = Object.entries(value)[0];\n\n      if (\n        [\"$gt\", \"$gte\", \"$lt\", \"$lte\"].includes(operator) &&\n        typeof operand !== \"number\"\n      ) {\n        throw new ChromaValueError(\n          `Expected operand value to be a number for ${operator}, but got ${typeof operand}`,\n        );\n      }\n\n      if ([\"$in\", \"$nin\"].includes(operator) && !Array.isArray(operand)) {\n        throw new ChromaValueError(\n          `Expected operand value to be an array for ${operator}, but got ${operand}`,\n        );\n      }\n\n      if (\n        [\"$contains\", \"$not_contains\"].includes(operator) &&\n        ![\"string\", \"number\", \"boolean\"].includes(typeof operand)\n      ) {\n        throw new ChromaValueError(\n          `Expected operand value to be a string, number, or boolean for ${operator}, but got ${typeof operand}`,\n        );\n      }\n\n      if (\n        ![\n          \"$gt\",\n          \"$gte\",\n          \"$lt\",","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L571-L607","documentation":"$in and $nin require their operand to be an array; validateWhere throws when it is not. A scalar, object, or string value for these set-membership operators fails the Array.isArray check client-side. Wrap the value(s) in a list before the call.","triggerScenarios":"where: { genre: { $in: 'sci-fi' } } — single value not wrapped. { $nin: { genre: 'x' } }. A variable that is sometimes scalar: { $in: selected } where selected = 'sci-fi'.","commonSituations":"Single-select UIs producing one value where the filter template expects a list; API params accepting both scalar and array forms; copy-pasting $eq syntax into $in.","solutions":["Always wrap: { $in: ['sci-fi'] }.","Normalize inputs: const list = Array.isArray(v) ? v : [v].","Use $eq for exact single matches instead of $in with a scalar."],"exampleFix":"// before\nwhere: { genre: { $in: selectedGenre } } // selectedGenre = 'sci-fi'\n\n// after\nwhere: { genre: { $in: Array.isArray(selectedGenre) ? selectedGenre : [selectedGenre] } }","handlingStrategy":"validation","validationCode":"const toList = (v) => Array.isArray(v) ? v : [v];\nawait collection.query({ queryTexts, where: { genre: { $in: toList(selected) } } });","typeGuard":"const isInOperand = (v: unknown): v is unknown[] => Array.isArray(v);","tryCatchPattern":"try {\n  await collection.query({ queryTexts, where });\n} catch (e) {\n  if ((e as Error).message.includes('to be an array for')) {\n    // wrap the scalar in [ ] and retry\n  } else {\n    throw e;\n  }\n}","preventionTips":["Normalize scalar-or-array inputs with an ensureArray() helper.","Reserve $in/$nin for lists; use $eq for single values.","Keep UI state for multi-selects always as arrays."],"tags":["where-filter","validation","set-operators"],"backgroundTag":"invalid-where-clause","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}