{"record":{"id":"44e9d218023b4212","repo":"mastra-ai/mastra","slug":"tried-to-create-embedding-index-but-no-vector-db-i","errorCode":null,"errorMessage":"Tried to create embedding index but no vector db is attached to this Memory instance.","messagePattern":"Tried to create embedding index but no vector db is attached to this Memory instance\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/memory/memory.ts","lineNumber":351,"sourceCode":"   */\n  protected getEmbeddingIndexName(dimensions?: number): string {\n    const defaultDimensions = 1536;\n    const usedDimensions = dimensions ?? defaultDimensions;\n    const isDefault = usedDimensions === defaultDimensions;\n    const separator = this.vector?.indexSeparator ?? '_';\n    return isDefault ? `memory${separator}messages` : `memory${separator}messages${separator}${usedDimensions}`;\n  }\n\n  protected async createEmbeddingIndex(\n    dimensions?: number,\n    config?: MemoryConfigInternal,\n  ): Promise<{ indexName: string }> {\n    const defaultDimensions = 1536;\n    const usedDimensions = dimensions ?? defaultDimensions;\n    const indexName = this.getEmbeddingIndexName(dimensions);\n\n    if (typeof this.vector === `undefined`) {\n      throw new Error(`Tried to create embedding index but no vector db is attached to this Memory instance.`);\n    }\n\n    // Get index configuration from memory config\n    const semanticConfig = typeof config?.semanticRecall === 'object' ? config.semanticRecall : undefined;\n    const indexConfig = semanticConfig?.indexConfig;\n\n    // Base parameters that all vector stores support\n    const createParams: any = {\n      indexName,\n      dimension: usedDimensions,\n      ...(indexConfig?.metric && { metric: indexConfig.metric }),\n    };\n\n    // Add PG-specific configuration if provided\n    // Only PG vector store will use these parameters\n    if (indexConfig && (indexConfig.type || indexConfig.ivf || indexConfig.hnsw)) {\n      createParams.indexConfig = {};\n      if (indexConfig.type) createParams.indexConfig.type = indexConfig.type;","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/memory/memory.ts#L333-L369","documentation":"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.","triggerScenarios":"Calling memory.createEmbeddingIndex(dimensions?, config?) on a Memory instance that was constructed without a vector store in its config.","commonSituations":"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.","solutions":["Attach a vector store in the Memory config, e.g. vector: new PgVector(connectionString).","Only call createEmbeddingIndex on Memory instances configured with vector storage.","Check memory.vector (or hasOwnStorage-style accessors) before calling createEmbeddingIndex."],"exampleFix":"// before\nconst memory = new Memory({ storage, options: { semanticRecall: true } });\nawait memory.createEmbeddingIndex(); // throws\n\n// after\nconst memory = new Memory({\n  storage,\n  vector: new PgVector(process.env.DATABASE_URL),\n  options: { semanticRecall: true },\n});\nawait memory.createEmbeddingIndex();","handlingStrategy":"validation","validationCode":"if (typeof memory.vector === 'undefined') {\n  throw new Error('Attach a vector store to Memory before createEmbeddingIndex');\n}\nawait memory.createEmbeddingIndex();","typeGuard":"function hasVector(m) { return typeof m.vector !== 'undefined'; }","tryCatchPattern":null,"preventionTips":["Provision vector stores in the same config object as Memory, never separately.","Run index-setup scripts against the same Memory factory used at runtime.","Prefer letting semanticRecall auto-create indexes over manual createEmbeddingIndex calls."],"tags":["memory","vector-store","semantic-recall","configuration"],"backgroundTag":"missing-vector-store","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}