{"record":{"id":"96e8dcb82a2f1964","repo":"mem0ai/mem0","slug":"client-not-initialized","errorCode":null,"errorMessage":"Client not initialized","messagePattern":"Client not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/vertexai.ts","lineNumber":155,"sourceCode":"\n  private formatInstance(text: string, taskType: string) {\n    // task_type must live on the instance (snake_case), not in `parameters`.\n    // Vertex silently ignores an unknown `parameters.taskType`, which would\n    // fall back to the model's default task type. This mirrors the Python SDK's\n    // TextEmbeddingInput(text=..., task_type=...).\n    return {\n      content: text,\n      task_type: taskType,\n    };\n  }\n\n  async embed(\n    text: string,\n    memoryAction?: \"add\" | \"update\" | \"search\",\n  ): Promise<number[]> {\n    await this.initClient();\n    if (!this.client || !this.helpers) {\n      throw new Error(\"Client not initialized\");\n    }\n\n    let embeddingType = \"SEMANTIC_SIMILARITY\";\n    if (memoryAction !== undefined) {\n      if (!(memoryAction in this.embeddingTypes)) {\n        throw new Error(`Invalid memory action: ${memoryAction}`);\n      }\n      embeddingType = this.embeddingTypes[memoryAction];\n    }\n\n    const instance = this.formatInstance(text, embeddingType);\n    const parameters = {\n      outputDimensionality: this.embeddingDims,\n    };\n\n    const [response] = await this.client.predict({\n      endpoint: this.endpoint(),\n      instances: [this.helpers.toValue(instance) as any],","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/vertexai.ts#L137-L173","documentation":"After await initClient() resolves, embed() double-checks that this.client and this.helpers were set by createClient(). Because initClient() memoizes and createClient() assigns both fields only on success, this branch is a defensive invariant guard that is effectively unreachable in practice; hitting it indicates an internal state bug (e.g. a subclass or monkey-patch overriding initClient) rather than a configuration problem.","triggerScenarios":"Subclassing VertexAIEmbedder and overriding initClient() without setting client/helpers; a module-duplication issue where two copies of the class share state; memory corruption of instance fields. Normal API/credential failures throw earlier inside createClient().","commonSituations":"Custom forks of the SDK; test doubles that stub initClient; practically never seen in stock usage.","solutions":["Do not override or stub initClient(); if you subclass, call super behavior or set client/helpers yourself","Ensure a single copy of mem0ai/oss is loaded (check for duplicate node_modules)","If it reproduces with stock code, report an issue with the SDK version and stack trace"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isClientNotInitialized(err: unknown): boolean {\n  return err instanceof Error && err.message === \"Client not initialized\";\n}","tryCatchPattern":"catch (err) {\n  if (err instanceof Error && err.message === \"Client not initialized\") {\n    // Internal invariant: recreate the embedder instance and retry once\n    embedder = new VertexAIEmbedder(cfg);\n    return await embedder.embed(text);\n  }\n  throw err;\n}","preventionTips":["Do not subclass/stub initClient; use config.client injection for test doubles","Keep a single SDK copy in node_modules","Report occurrences with a stack trace - stock code should not reach this branch"],"tags":["vertexai","internal-invariant","defensive","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}