mem0ai/mem0 · error · Error

$not filter value must be an array.

Error message

$not filter value must be an array.

What it means

The $not operator in the Neptune Analytics provider must be an array of sub-filters: each entry is built, then negated via negateVertexFilter, and combined with andAll (i.e., none of the entries may match). A non-array value cannot be mapped/negated, so the store throws with a specific message distinguishing it from the $and/$or guard.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts:509

      if (key === "$and" || key === "$or") {
        if (!Array.isArray(value)) {
          throw new Error(`${key} filter value must be an array.`);
        }

        const nested = value
          .map((entry) => this.buildMetadataVertexFilter(entry))
          .filter((entry): entry is NeptuneVertexFilter => !!entry);
        const joiner = key === "$and" ? "andAll" : "orAll";
        const combined = this.combineVertexFilters(joiner, nested);
        if (combined) {
          operations.push(combined);
        }
        continue;
      }

      if (key === "$not") {
        if (!Array.isArray(value)) {
          throw new Error("$not filter value must be an array.");
        }

        const nested = value
          .map((entry) => this.buildMetadataVertexFilter(entry))
          .filter((entry): entry is NeptuneVertexFilter => !!entry)
          .map((entry) => this.negateVertexFilter(entry));
        const combined = this.combineVertexFilters("andAll", nested);
        if (combined) {
          operations.push(combined);
        }
        continue;
      }

      operations.push(this.buildFieldVertexFilter(key, value));
    }

    return this.combineVertexFilters("andAll", operations);
  }

View on GitHub (pinned to 001c235229)

Solutions

  1. Wrap in an array: { $not: [{ user_id: 'u1' }] }.
  2. Keep nesting consistent when composing: every $and/$or/$not node's value is an array of nodes.
  3. Add a recursive assertValidNeptuneFilter() in shared code paths.

Example fix

// before
store.search(q, 5, { $not: { user_id: 'u1' } }); // throws

// after
store.search(q, 5, { $not: [{ user_id: 'u1' }] });
Defensive patterns

Strategy: validation

Validate before calling

if (filters.$not !== undefined && !Array.isArray(filters.$not)) {
  filters = { ...filters, $not: [filters.$not] };
}

Type guard

const isNotArray = (v: unknown): v is NeptuneFilters[] => Array.isArray(v) && v.length > 0;

Try / catch

try { await store.search(q, 5, filters); }
catch (e) {
  if (e instanceof Error && e.message === '$not filter value must be an array.') {
    return store.search(q, 5, { ...filters, $not: [filters.$not] });
  }
  throw e;
}

Prevention

When it happens

Trigger: search(q, k, { $not: { user_id: 'u1' } }) instead of { $not: [{ user_id: 'u1' }] }; nested structures like { $and: [{ $not: { tag: 'x' } }] } where the inner $not value is a dict.

Common situations: Mongo-style $not: { $eq: value } habits; filter trees generated programmatically where single-element arrays got unwrapped.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/a50af8a208f3ae7b. Report an issue: GitHub.