mem0ai/mem0 · error
OR operator requires a non-empty list of conditions
Error message
OR operator requires a non-empty list of conditions
What it means
Thrown during metadata filter preprocessing when the OR key's value is not an array or is an empty array. OR conditions are passed through to the vector store as a $or list, and an empty or malformed list would produce an invalid query. Unlike AND, the emptiness check is explicit.
Source
Thrown at mem0-ts/src/oss/src/memory/index.ts:2161
}
return result;
};
for (const [key, value] of Object.entries(metadataFilters)) {
if (key === "AND") {
// Logical AND: combine multiple conditions
if (!Array.isArray(value)) {
throw new Error("AND operator requires a list of conditions");
}
for (const condition of value) {
for (const [subKey, subValue] of Object.entries(condition)) {
Object.assign(processedFilters, processCondition(subKey, subValue));
}
}
} else if (key === "OR") {
// Logical OR: Pass through to vector store for implementation-specific handling
if (!Array.isArray(value) || value.length === 0) {
throw new Error(
"OR operator requires a non-empty list of conditions",
);
}
processedFilters["$or"] = [];
for (const condition of value) {
const orCondition: Record<string, any> = {};
for (const [subKey, subValue] of Object.entries(
condition as Record<string, any>,
)) {
Object.assign(orCondition, processCondition(subKey, subValue));
}
processedFilters["$or"].push(orCondition);
}
} else if (key === "NOT") {
// Logical NOT: Pass through to vector store for implementation-specific handling
if (!Array.isArray(value) || value.length === 0) {
throw new Error(
"NOT operator requires a non-empty list of conditions",View on GitHub (pinned to 001c235229)
Solutions
- Provide a non-empty array: OR: [{ tag: { equals: 'a' } }, { tag: { equals: 'b' } }]
- If the dynamic OR list can be empty, fall back to omitting the OR key entirely
- For a single OR condition, still use the array form
Example fix
// before
filters: { user_id: 'u1', OR: [] }
// after
const tagConds = tags.map(t => ({ tag: { equals: t } }));
const filters = { user_id: 'u1', ...(tagConds.length ? { OR: tagConds } : {}) }; Defensive patterns
Strategy: type-guard
Validate before calling
function orKey(conds: unknown[]) { return Array.isArray(conds) && conds.length ? { OR: conds } : {}; } Type guard
const isNonEmptyConditionArray = (v: unknown): v is object[] => Array.isArray(v) && v.length > 0 && v.every((c) => typeof c === 'object' && c !== null);
Prevention
- Only add OR to filters when the condition array is non-empty
- Treat empty dynamic OR lists as 'no filter' rather than an empty array
When it happens
Trigger: Writing OR: {} (object), OR: [] (empty list), or OR: undefined after dynamic filter construction drops the conditions array.
Common situations: Building OR from a list of user-chosen tags that turns out empty; copying the AND object shape for OR; programmatically collapsing a one-element OR incorrectly.
Related errors
- Unsupported metadata filter operator: ${operator}
- AND operator requires a list of conditions
- NOT operator requires a non-empty list of conditions
- One of the filters: userId, agentId or runId is required!
- filters must contain at least one of: user_id, agent_id, run
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/8ca0782a4e19cda0.
Report an issue: GitHub.