mastra-ai/mastra · error

Tried to upsert embeddings but this Memory instance doesn't

Error message

Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.

What it means

After generating embeddings for semantic recall, Memory upserts them into a vector store. If this.vector is undefined — i.e. no vector DB was passed to the Memory constructor — the upsert throws. Storage alone holds messages; the vector store is a separate, required dependency for semantic recall writes.

Source

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

              embeddings: result.embeddings,
              metadata: result.chunks.map(() => ({
                ...threadMetadata,
                message_id: message.id,
                thread_id: message.threadId,
                resource_id: message.resourceId,
                role: message.role,
                content: textForEmbedding,
                created_at:
                  message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt),
              })),
            });
          }),
        );

        // Batch all vectors into a single upsert call to avoid pool exhaustion
        if (embeddingData.length > 0 && dimension !== undefined) {
          if (typeof this.vector === `undefined`) {
            throw new Error(`Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.`);
          }

          const { indexName } = await this.createEmbeddingIndex(dimension, config);

          // Flatten all embeddings and metadata into single arrays
          const allVectors: number[][] = [];
          const allMetadata: Array<
            Record<string, unknown> & {
              message_id: string;
              thread_id: string | undefined;
              resource_id: string | undefined;
            }
          > = [];

          for (const data of embeddingData) {
            allVectors.push(...data.embeddings);
            allMetadata.push(...data.metadata);
          }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Attach a vector store: new Memory({ storage, embedder, vector: new LibSQLVector({ connectionUrl: ... }) }) (or PgVector, etc.).
  2. If you don't want semantic recall, disable semanticRecall in the Memory config so no vector writes occur.
  3. Check that your config builder actually includes the vector option rather than only storage/embedder.

Example fix

// before
const memory = new Memory({ storage, embedder: new FastEmbed() });
// after
import { LibSQLVector } from '@mastra/libsql';
const memory = new Memory({ storage, embedder: new FastEmbed(), vector: new LibSQLVector({ connectionUrl: 'file:./vectors.db' }) });
Defensive patterns

Strategy: validation

Validate before calling

if (!memoryConfig.vector) {
  throw new Error('Memory requires a vector store for semantic recall embedding writes');
}
const memory = new Memory({ storage, embedder, vector: memoryConfig.vector });

Type guard

function hasVector(m: Memory): boolean {
  return typeof (m as unknown as { vector?: unknown }).vector !== 'undefined';
}

Try / catch

try {
  await memory.remember({ threadId, resourceId, messages });
} catch (e) {
  if (e instanceof Error && e.message.includes("doesn't have an attached vector db")) {
    console.error('Configure a vector store (e.g. LibSQLVector) on the Memory instance.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling remember() (which saves message embeddings) with a Memory configured with storage and embedder but no vector store in the options.

Common situations: Using Memory({ storage, embedder }) and expecting embeddings to live in the relational store; omitting the vector option when migrating from a setup where it was provided; config objects built conditionally dropping vector.

Related errors


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