mastra-ai/mastra · error

searchMessages requires a vector store. Configure vector and

Error message

searchMessages requires a vector store. Configure vector and embedder on your Memory instance.

What it means

Memory.searchMessages() performs vector similarity search over stored messages, which requires both a vector store and an embedder. The library throws this error when the Memory instance was constructed without a `vector` store configured, so it cannot execute the semantic query.

Source

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

    resourceId: string;
    topK?: number;
    filter?: {
      threadId?: string;
      observedAfter?: Date;
      observedBefore?: Date;
    };
  }): Promise<{
    results: Array<{
      threadId: string;
      score: number;
      groupId?: string;
      range?: string;
      text?: string;
      observedAt?: Date;
    }>;
  }> {
    if (!this.vector) {
      throw new Error('searchMessages requires a vector store. Configure vector and embedder on your Memory instance.');
    }

    const { embeddings, dimension } = await this.embedMessageContent(query);
    const { indexName } = await this.createObservationEmbeddingIndex(dimension);

    const vectorFilter: VectorFilter = { resource_id: resourceId };
    if (filter?.threadId) {
      vectorFilter.thread_id = filter.threadId;
    }
    if (filter?.observedAfter || filter?.observedBefore) {
      vectorFilter.observed_at = {
        ...(filter.observedAfter ? { $gt: filter.observedAfter.toISOString() } : {}),
        ...(filter.observedBefore ? { $lt: filter.observedBefore.toISOString() } : {}),
      };
    }

    const queryResults: Array<{
      threadId: string;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Construct Memory with both `vector` and `embedder` options (e.g. new Memory({ storage, vector: new PgVector(...), embedder: new FastEmbed() }))
  2. If semantic search is not needed, use thread-level message retrieval APIs instead of searchMessages
  3. Verify the Memory instance you are calling is the same configured one (not a second, unconfigured instance created elsewhere)

Example fix

// before
const memory = new Memory({ storage: new PostgresStore(...) });
await memory.searchMessages({ query, resourceId });

// after
const memory = new Memory({
  storage: new PostgresStore(...),
  vector: new PgVector(process.env.DATABASE_URL),
  embedder: new FastEmbed(),
});
await memory.searchMessages({ query, resourceId });
Defensive patterns

Strategy: validation

Validate before calling

function canSearchMessages(memory: Memory): boolean {
  return !!(memory as any).vector;
}
if (!canSearchMessages(memory)) {
  throw new Error('Configure vector and embedder on Memory before calling searchMessages');
}

Type guard

function hasVectorStore(memory: Memory): memory is Memory & { vector: unknown } {
  return Boolean((memory as any).vector);
}

Try / catch

try {
  await memory.searchMessages(args);
} catch (err) {
  if (err instanceof Error && err.message.includes('requires a vector store')) {
    return { messages: [] }; // semantic search unavailable; degrade gracefully
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling memory.searchMessages(...) on a Memory instance created without passing a `vector` (and implicitly `embedder`) option; or constructing Memory with only a storage adapter.

Common situations: Upgrading from a setup that only used `storage` to semantic recall; copying Memory config from examples that omit vector store wiring; forgetting to instantiate an embedder (e.g. openai text-embedding model) alongside a vector DB (pgvector, Chroma, etc.).

Related errors


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