{"record":{"id":"c06460fc95bd2049","repo":"mem0ai/mem0","slug":"failed-to-auto-detect-embedding-dimension-from-pro","errorCode":null,"errorMessage":"Failed to auto-detect embedding dimension from provider '${this.config.embedder.provider}': ${error.message}. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.","messagePattern":"Failed to auto-detect embedding dimension from provider '(.+?)': (.+?)\\. Please set 'dimension' in vectorStore\\.config or 'embeddingDims' in embedder\\.config explicitly\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/memory/index.ts","lineNumber":274,"sourceCode":"    // and initialize it. All public methods await this before proceeding.\n    this._initPromise = this._autoInitialize().catch((error) => {\n      this._initError =\n        error instanceof Error ? error : new Error(String(error));\n      console.error(this._initError);\n    });\n  }\n\n  /**\n   * If no explicit dimension was provided, runs a probe embedding to\n   * detect it. Then creates and initializes the vector store.\n   */\n  private async _autoInitialize(): Promise<void> {\n    if (!this.config.vectorStore.config.dimension) {\n      try {\n        const probe = await this.embedder.embed(\"dimension probe\");\n        this.config.vectorStore.config.dimension = probe.length;\n      } catch (error: any) {\n        throw new Error(\n          `Failed to auto-detect embedding dimension from provider '${this.config.embedder.provider}': ${error.message}. ` +\n            `Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.`,\n        );\n      }\n    }\n\n    this.vectorStore = VectorStoreFactory.create(\n      this.config.vectorStore.provider,\n      this.config.vectorStore.config,\n    );\n\n    // The vector store constructor may fire initialize() asynchronously\n    // (e.g. Qdrant). Explicitly await it here to guarantee the backing\n    // store (collections, tables, etc.) is ready before any public method\n    // attempts to read or write.\n    await this.vectorStore.initialize();\n\n    await this._initializeTelemetry();","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/memory/index.ts#L256-L292","documentation":"During lazy first-use initialization, when no vectorStore dimension and no embedder embeddingDims were configured, Memory runs a probe embedding ('dimension probe') to infer the dimension; if that probe call fails, this error wraps the embedder's failure and tells you to set the dimension explicitly. The embedded message identifies both the embedder provider and the original failure.","triggerScenarios":"Constructing Memory without vectorStore.config.dimension or embedder.config.embeddingDims, then triggering the first vector operation, while the embedder fails — e.g. OpenAI embedder with a missing/invalid API key, unreachable embeddings endpoint, wrong model name, or a provider whose embed() throws.","commonSituations":"Quick-start configs that omit dimension because 'auto-detect' usually works, but the embedding provider credentials are absent in CI/deployment; embedder model typos; local embedding models not downloaded; network egress blocked so the probe request fails.","solutions":["Fix the embedder first: check the original error.message (e.g. OpenAI 401 = bad key, 404 = bad embedding model).","Or bypass the probe by pinning the dimension: vectorStore.config.dimension = 1536 (text-embedding-3-small) or embedder.config.embeddingDims.","Ensure the embedder's API key/env vars are present in the runtime performing the first operation (initialization is lazy, not at construction).","For local embedders, confirm model weights are downloaded/accessible before first use."],"exampleFix":"// before\nconst memory = new Memory({\n  embedder: { provider: 'openai', config: {} }, // no key in env -> probe fails\n  vectorStore: { provider: 'memory', config: {} },\n});\nawait memory.add('hi', { filters: { userId: 'u1' } }); // throws auto-detect error\n\n// after\nconst memory = new Memory({\n  embedder: { provider: 'openai', config: { apiKey: process.env.OPENAI_API_KEY } },\n  vectorStore: { provider: 'memory', config: { dimension: 1536 } }, // explicit\n});","handlingStrategy":"validation","validationCode":"const KNOWN_DIMS: Record<string, number> = {\n  'text-embedding-3-small': 1536,\n  'text-embedding-3-large': 3072,\n};\nfunction withExplicitDimension(config: MemoryConfig, model: string): MemoryConfig {\n  return {\n    ...config,\n    vectorStore: {\n      ...config.vectorStore,\n      config: { ...config.vectorStore.config, dimension: KNOWN_DIMS[model] },\n    },\n  };\n}","typeGuard":null,"tryCatchPattern":"try {\n  await memory.add(text, opts);\n} catch (err) {\n  if (err instanceof Error && /auto-detect embedding dimension/.test(err.message)) {\n    // embedder creds/model broken — surface the embedded cause, don't retry\n    throw new Error(`Embedder misconfigured: ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Always pin dimension (or embeddingDims) in production configs instead of relying on the probe.","Verify embedder credentials with a one-off embed() call in your startup checks.","Remember initialization is lazy — test the first memory operation in the same env as production."],"tags":["embeddings","vector-store","initialization","dimension","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}