mastra-ai/mastra · error · Error

Tried to create embedding index but no vector db is attached

Error message

Tried to create embedding index but no vector db is attached to this Memory instance.

What it means

createEmbeddingIndex creates the vector index used for semantic recall but requires a vector database attached to Memory. This plain Error is thrown when this.vector is undefined at index-creation time. Unlike the constructor check (which fires for semanticRecall configs), this guards direct calls to createEmbeddingIndex on a Memory without a vector store.

Source

Thrown at packages/core/src/memory/memory.ts:351

   */
  protected getEmbeddingIndexName(dimensions?: number): string {
    const defaultDimensions = 1536;
    const usedDimensions = dimensions ?? defaultDimensions;
    const isDefault = usedDimensions === defaultDimensions;
    const separator = this.vector?.indexSeparator ?? '_';
    return isDefault ? `memory${separator}messages` : `memory${separator}messages${separator}${usedDimensions}`;
  }

  protected async createEmbeddingIndex(
    dimensions?: number,
    config?: MemoryConfigInternal,
  ): Promise<{ indexName: string }> {
    const defaultDimensions = 1536;
    const usedDimensions = dimensions ?? defaultDimensions;
    const indexName = this.getEmbeddingIndexName(dimensions);

    if (typeof this.vector === `undefined`) {
      throw new Error(`Tried to create embedding index but no vector db is attached to this Memory instance.`);
    }

    // Get index configuration from memory config
    const semanticConfig = typeof config?.semanticRecall === 'object' ? config.semanticRecall : undefined;
    const indexConfig = semanticConfig?.indexConfig;

    // Base parameters that all vector stores support
    const createParams: any = {
      indexName,
      dimension: usedDimensions,
      ...(indexConfig?.metric && { metric: indexConfig.metric }),
    };

    // Add PG-specific configuration if provided
    // Only PG vector store will use these parameters
    if (indexConfig && (indexConfig.type || indexConfig.ivf || indexConfig.hnsw)) {
      createParams.indexConfig = {};
      if (indexConfig.type) createParams.indexConfig.type = indexConfig.type;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Attach a vector store in the Memory config, e.g. vector: new PgVector(connectionString).
  2. Only call createEmbeddingIndex on Memory instances configured with vector storage.
  3. Check memory.vector (or hasOwnStorage-style accessors) before calling createEmbeddingIndex.

Example fix

// before
const memory = new Memory({ storage, options: { semanticRecall: true } });
await memory.createEmbeddingIndex(); // throws

// after
const memory = new Memory({
  storage,
  vector: new PgVector(process.env.DATABASE_URL),
  options: { semanticRecall: true },
});
await memory.createEmbeddingIndex();
Defensive patterns

Strategy: validation

Validate before calling

if (typeof memory.vector === 'undefined') {
  throw new Error('Attach a vector store to Memory before createEmbeddingIndex');
}
await memory.createEmbeddingIndex();

Type guard

function hasVector(m) { return typeof m.vector !== 'undefined'; }

Prevention

When it happens

Trigger: Calling memory.createEmbeddingIndex(dimensions?, config?) on a Memory instance that was constructed without a vector store in its config.

Common situations: Manual index provisioning scripts that create Memory without vector storage; renaming/refactoring config objects so the vector field is lost; assuming createEmbeddingIndex works with a storage-only Memory.

Related errors


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