{"record":{"id":"7a231a28ebb0832e","repo":"chroma-core/chroma","slug":"expected-where-operand-value-to-be-a-non-empty-l","errorCode":null,"errorMessage":"Expected 'where' operand value to be a non-empty list and all values to be of the same type","messagePattern":"Expected 'where' operand value to be a non-empty list and all values to be of the same type","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":636,"sourceCode":"          `Expected operator to be one of $gt, $gte, $lt, $lte, $ne, $eq, $in, $nin, $contains, $not_contains, but got ${operator}`,\n        );\n      }\n\n      if (\n        ![\"string\", \"number\", \"boolean\"].includes(typeof operand) &&\n        !Array.isArray(operand)\n      ) {\n        throw new ChromaValueError(\n          \"Expected operand value to be a string, number, boolean, or a list of those types\",\n        );\n      }\n\n      if (\n        Array.isArray(operand) &&\n        (operand.length === 0 ||\n          !operand.every((item) => typeof item === typeof operand[0]))\n      ) {\n        throw new ChromaValueError(\n          \"Expected 'where' operand value to be a non-empty list and all values to be of the same type\",\n        );\n      }\n    }\n  });\n};\n\n/**\n * Validates a where document clause for document content filtering.\n * @param whereDocument - Where document clause to validate\n * @throws ChromaValueError if the clause is malformed\n */\nexport const validateWhereDocument = (whereDocument: WhereDocument) => {\n  if (typeof whereDocument !== \"object\") {\n    throw new ChromaValueError(\n      \"Expected 'whereDocument' to be a non-empty object\",\n    );\n  }","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L618-L654","documentation":"Array operands in where operator expressions must be non-empty and type-homogeneous — the same rule as metadata lists. An empty $in list ({$in: []}) or a mixed list ({$in: [1, 'a']}) throws ChromaValueError client-side. Homogeneity is checked against typeof of the first element.","triggerScenarios":"where: { genre: { $in: [] } } — empty selection from a faceted UI. { $in: ['1', 2] } — query-param values partially converted to numbers.","commonSituations":"Multi-select widgets where the user selects nothing; merging typed and stringified values; a default empty list reaching the query unchecked.","solutions":["Skip the filter (or the query) when the list is empty.","Normalize element types: list.map(Number) or list.map(String).","Check non-empty and uniform typeof before issuing the query."],"exampleFix":"// before\nconst where = { genre: { $in: selected } }; // selected = []\n\n// after\nconst where = selected.length ? { genre: { $in: selected } } : undefined;","handlingStrategy":"validation","validationCode":"const cleanIn = (field, list) => list.length && list.every(v => typeof v === typeof list[0])\n  ? { [field]: { $in: list } }\n  : undefined;\nconst where = cleanIn('genre', selected) ?? {}; // omit filter when invalid/empty","typeGuard":"const isUniformList = (v: unknown): v is [unknown, ...unknown[]] =>\n  Array.isArray(v) && v.length > 0 && v.every(item => typeof item === typeof v[0]);","tryCatchPattern":"try {\n  await collection.query({ queryTexts, where });\n} catch (e) {\n  if ((e as Error).message.includes('non-empty list and all values')) {\n    // drop the empty list or coerce mixed types to one type, then retry\n  } else {\n    throw e;\n  }\n}","preventionTips":["Skip empty $in/$nin filters instead of sending them.","Normalize list element types (map(Number)/map(String)) before querying.","Default multi-select state to 'no filter', not []."],"tags":["where-filter","validation","arrays"],"backgroundTag":"invalid-where-clause","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}