mem0ai/mem0 · error
NOT operator requires a non-empty list of conditions
Error message
NOT operator requires a non-empty list of conditions
What it means
Thrown during metadata filter preprocessing when the NOT key's value is not an array or is an empty array. Like OR, NOT is passed through to the vector store as a $not list; an empty or non-list value is rejected before the query is built. Structurally identical to the OR guard.
Source
Thrown at mem0-ts/src/oss/src/memory/index.ts:2178
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",
);
}
processedFilters["$not"] = [];
for (const condition of value) {
const notCondition: Record<string, any> = {};
for (const [subKey, subValue] of Object.entries(
condition as Record<string, any>,
)) {
Object.assign(notCondition, processCondition(subKey, subValue));
}
processedFilters["$not"].push(notCondition);
}
} else {
Object.assign(processedFilters, processCondition(key, value));
}
}
View on GitHub (pinned to 001c235229)
Solutions
- Provide a non-empty array: NOT: [{ tag: { equals: 'internal' } }]
- Omit the NOT key when the exclusion list is empty
- Share a helper that only adds AND/OR/NOT keys when their condition arrays are non-empty
Example fix
// before
filters: { user_id: 'u1', NOT: [] }
// after
const notConds = blocked.map(b => ({ tag: { equals: b } }));
const filters = { user_id: 'u1', ...(notConds.length ? { NOT: notConds } : {}) }; Defensive patterns
Strategy: type-guard
Validate before calling
function notKey(conds: unknown[]) { return Array.isArray(conds) && conds.length ? { NOT: 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 include NOT when the exclusion list has entries
- Share one helper for AND/OR/NOT that drops empty lists before calling the SDK
When it happens
Trigger: Writing NOT: {} or NOT: [], or a dynamically built exclusion list that ended up empty.
Common situations: Exclusion lists (blocked tags, muted users) that are usually populated but empty in some environments; using an object instead of an array by analogy with nested JSON filters.
Related errors
- Unsupported metadata filter operator: ${operator}
- AND operator requires a list of conditions
- OR 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/3df2ebd007542856.
Report an issue: GitHub.