mem0ai/mem0 · error · Error
Filter value for '${key}' must be an array.
Error message
Filter value for '${key}' must be an array. What it means
Operators that compare against a set (in / nin) compile to OpenSearch terms queries and therefore require their filter value to be an array. assertScalarArray both checks that the value is an array and validates every element is scalar, throwing this message when the array itself is missing.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/opensearch.ts:649
return keyword ? `${field}.keyword` : field;
}
// Filter values become OpenSearch term/terms/range/wildcard leaves. Allowing
// an object here lets a caller inject raw query parameters (e.g. a `term`
// object form with `boost`/`case_insensitive`), so reject non-scalar leaves.
// Mirrors the Python SDK's `_validate_filter` scalar allow-list (PR #5986).
private assertScalarValue(key: string, value: any): void {
if (value !== null && typeof value === "object") {
throw new Error(
`Filter value for '${key}' must be a string, number, or boolean, got ` +
`${Array.isArray(value) ? "an array" : "an object"}.`,
);
}
}
private assertScalarArray(key: string, value: any): void {
if (!Array.isArray(value)) {
throw new Error(`Filter value for '${key}' must be an array.`);
}
value.forEach((item) => this.assertScalarValue(key, item));
}
}
View on GitHub (pinned to 001c235229)
Solutions
- Always pass an array for in/nin: { tag: { in: ['prod'] } }.
- Normalize input: const arr = Array.isArray(v) ? v : [v]; before building the filter.
- Add a type guard on user-supplied filter values before calling search.
Example fix
// before
filters = { tag: { in: 'prod' } };
// after
filters = { tag: { in: ['prod'] } }; Defensive patterns
Strategy: validation
Validate before calling
for (const [op, v] of Object.entries(ops)) {
if ((op === 'in' || op === 'nin') && !Array.isArray(v)) {
ops[op] = [v]; // normalize scalar to array
}
} Type guard
const isScalarArray = (v: unknown): v is (string | number | boolean)[] => Array.isArray(v) && v.every((i) => i === null || ['string','number','boolean'].includes(typeof i));
Prevention
- Always wrap in/nin values in arrays
- Normalize single user inputs to arrays
- Reuse one filter-builder helper across the app
When it happens
Trigger: Passing { tag: { in: 'prod' } } (scalar instead of array) or { tag: { nin: { env: 'prod' } } } to search/list filters on the OpenSearch store.
Common situations: Accepting a single value from user input and not normalizing to array; config files that collapse one-element lists; porting from backends that accept a scalar for membership tests.
Related errors
- ${key} filter value must be an array.
- Top-level entity parameters [${invalidKeys.join(", ")}] are
- Invalid ${name}: cannot be empty or whitespace-only. Provide
- Invalid ${name}: cannot contain whitespace. Provide a valid
- AND filter value must be a list of filter dicts, got ${typeo
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/cb566dcfe38f0782.
Report an issue: GitHub.