mastra-ai/mastra · error

Memory error: Resource-scoped semantic recall is enabled but

Error message

Memory error: Resource-scoped semantic recall is enabled but no resourceId was provided. Either provide a resourceId or explicitly set semanticRecall.scope to 'thread'.

What it means

If semantic recall is enabled at resource scope (semanticRecall === true or an object with scope !== 'thread') and a vector search string is present but no resourceId was provided, recall cannot compute the resource_id filter and throws this guidance error instead of silently failing.

Source

Thrown at packages/memory/src/index.ts:707

      const vectorConfig =
        typeof config?.semanticRecall === `boolean`
          ? {
              topK: defaultTopK,
              messageRange: defaultRange,
            }
          : {
              topK: config?.semanticRecall?.topK ?? defaultTopK,
              messageRange: config?.semanticRecall?.messageRange ?? defaultRange,
            };

      const resourceScope =
        (typeof config?.semanticRecall === 'object' && config?.semanticRecall?.scope !== `thread`) ||
        config.semanticRecall === true;

      // Guard: If resource-scoped semantic recall is enabled but no resourceId is provided, throw an error
      if (resourceScope && !resourceId && config?.semanticRecall && vectorSearchString) {
        throw new Error(
          `Memory error: Resource-scoped semantic recall is enabled but no resourceId was provided. ` +
            `Either provide a resourceId or explicitly set semanticRecall.scope to 'thread'.`,
        );
      }

      let usage: { tokens: number } | undefined;

      // If history is disabled and there's no semantic recall to perform, return empty immediately
      if (historyDisabledByConfig && (!config.semanticRecall || !vectorSearchString || !this.vector)) {
        const result = {
          messages: [],
          usage: undefined,
          total: 0,
          page: page ?? 0,
          perPage: 0,
          hasMore: false,
        };
        span?.end({ output: { success: true }, attributes: { messageCount: 0 } });

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass resourceId to recall()
  2. Set semanticRecall: { scope: 'thread' } explicitly to keep thread-scoped recall when resourceId is unavailable
  3. Update agent memory config so scope matches what callers actually provide

Example fix

// before
await memory.recall({ threadId, query: 'shipping status' });
// after
await memory.recall({ threadId, resourceId, query: 'shipping status' });
// or
await memory.recall({ threadId, query: 'shipping status', memoryConfig: { semanticRecall: { scope: 'thread' } } });
Defensive patterns

Strategy: validation

Validate before calling

if (semanticRecallEnabledAtResourceScope && queryText && !resourceId) {
  throw new Error('resourceId is required for resource-scoped semantic recall');
}

Try / catch

try {
  await memory.recall({ threadId, resourceId, query });
} catch (e) {
  if (e instanceof Error && e.message.includes('Resource-scoped semantic recall is enabled but no resourceId')) {
    // fall back to thread-scoped recall or surface a config error
  } else throw e;
}

Prevention

When it happens

Trigger: memory.recall({ threadId }) with semanticRecall: true or { scope: 'resource' } and query text, but resourceId omitted; also agent memory config defaulting scope to 'resource' while caller passes only threadId.

Common situations: Upgrading Mastra where semanticRecall: true now implies resource scope; agent configs that changed scope defaults; code paths that always had resourceId removed in a refactor.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/d16287d9ab3285af. Report an issue: GitHub.