mastra-ai/mastra · error
Tried to query vector index
Error message
Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db. What it means
During recall's semantic search the embeddings are queried against a vector index, but the Memory instance has no vector store attached (this.vector undefined). The error is thrown defensively right before querying, naming the index that would have been used.
Solutions
- Attach a vector store: pass `vector: new PGVector(...)`, `new FastVector(...)`, etc. when constructing Memory
- Ensure the conditional that creates the vector store actually runs (check env vars/feature flags)
- Disable semanticRecall if vector search is not intended
Example fix
// before
const memory = new Memory({ storage: store, embedder: embedder });
// after
import { PGVector } from '@mastra/pg';
const memory = new Memory({ storage: store, embedder: embedder, vector: new PGVector({ connectionString: process.env.DATABASE_URL }) }); Defensive patterns
Strategy: validation
Validate before calling
if (!memoryVector) throw new Error('Memory requires a vector store for semanticRecall; pass vector: new ...Vector(...)'); Type guard
function hasVectorStore(m: { vector?: unknown }): boolean {
return m.vector !== undefined && m.vector !== null;
} Prevention
- Always construct Memory with a vector store when semanticRecall is enabled
- Verify vector store construction errors/env vars at startup, not first recall
- Add a startup assertion that memory.vector is defined when using semantic recall
When it happens
Trigger: Configuring semanticRecall without providing a `vector` option to `new Memory({...})`, then triggering a vector search; vector store constructor failing silently or being conditionally omitted (e.g. missing env vars for the provider).
Common situations: Copying Memory config examples without the vector field; vector store disabled when an API key env var is absent; switching storage backends that bundle a vector store to one that doesn't.
Related errors
- Tried to create embedding index but no vector db is…
- Memory error: Resource-scoped semantic recall is enabled…
- searchMessages requires a vector store. Configure vector…
- SEMANTIC_RECALL_MISSING_EMBEDDER
- SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/6885fa0a7302b4da.
Report an issue: GitHub.
Appendix: source
Thrown at packages/memory/src/index.ts:738
total: 0,
page: page ?? 0,
perPage: 0,
hasMore: false,
};
span?.end({ output: { success: true }, attributes: { messageCount: 0 } });
return result;
}
if (config?.semanticRecall && vectorSearchString && this.vector) {
const result = await this.embedMessageContent(vectorSearchString!);
usage = result.usage;
const { embeddings, dimension } = result;
const { indexName } = await this.createEmbeddingIndex(dimension, config);
await Promise.all(
embeddings.map(async embedding => {
if (typeof this.vector === `undefined`) {
throw new Error(
`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`,
);
}
const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
const userFilter = typeof config.semanticRecall === 'object' ? config.semanticRecall.filter : undefined;
const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
vectorResults.push(
...(await this.vector.query({
indexName,
queryVector: embedding,
topK: vectorConfig.topK,
filter: combinedFilter,
})),
);
}),
);View on GitHub (pinned to 75dd419e61)