Mintplex-Labs/anything-llm · warning

Maximum ${scope} memory limit (${limit}) reached.

Error message

Maximum ${scope} memory limit (${limit}) reached.

What it means

400 from POST /memories. Memory.create enforces per-scope caps — 5 global per user (GLOBAL_LIMIT) and 20 per user per workspace (WORKSPACE_LIMIT). When countForScope reports count >= limit, no row is written and {memory:null, message} returns, which the endpoint sends as 400. Scope comes from the body (default 'workspace'); counts are per-user in multi-user mode.

Source

Thrown at server/endpoints/memory.js:91

    [
      validatedRequest,
      flexUserRoleValid([ROLES.all]),
      memoryFeatureEnabled,
      validWorkspaceSlug,
    ],
    async (request, response) => {
      try {
        const user = await userFromSession(request, response);
        const workspace = response.locals.workspace;
        const { content, scope = "workspace" } = reqBody(request);
        const { memory, message } = await Memory.create({
          userId: user?.id,
          workspaceId: scope === "global" ? null : workspace.id,
          scope,
          content: content.trim(),
        });

        if (!memory) return response.status(400).json({ error: message });
        response.status(200).json({ memory });
      } catch (e) {
        console.error(e);
        return response.sendStatus(500);
      }
    }
  );

  app.put(
    "/memories/:memoryId",
    [
      validatedRequest,
      flexUserRoleValid([ROLES.all]),
      memoryFeatureEnabled,
      validateMemoryOwner,
    ],
    async (request, response) => {
      try {

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Delete or consolidate existing memories in that scope, then retry
  2. Prefer scope:'workspace' (limit 20) when cross-workspace recall is not required
  3. If the product needs more, raise Memory.GLOBAL_LIMIT / Memory.WORKSPACE_LIMIT in server/models/memory.js
  4. Have the client count current memories before offering the 'add memory' action

Example fix

// before
await fetch('/memories', { method: 'POST', body: JSON.stringify({ content, scope }) });
// after
const existing = memories.filter((m) => m.scope === scope);
const limit = scope === 'global' ? 5 : 20;
if (existing.length >= limit) { promptConsolidateOrDelete(); return; }
await fetch('/memories', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ content, scope }) });
Defensive patterns

Strategy: validation

Validate before calling

const LIMITS = { global: 5, workspace: 20 };
const inScope = memories.filter((m) => m.scope === scope);
if (inScope.length >= LIMITS[scope]) throw new Error(`Memory cap (${LIMITS[scope]}) reached — delete or consolidate first`);

Prevention

When it happens

Trigger: POST /memories {content, scope:'workspace'} when that user already holds 20 memories in that workspace, or {scope:'global'} with 5 global memories. Single-user mode counts under userId null.

Common situations: Memory extraction pipelines accumulating entries until the cap; users consolidating workspace memories into global and hitting the tighter 5-item cap.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/1a79adb237efa63f. Report an issue: GitHub.