mem0ai/mem0 · error · Error

Client not initialized

Error message

Client not initialized

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/embeddings/vertexai.ts:155

  private formatInstance(text: string, taskType: string) {
    // task_type must live on the instance (snake_case), not in `parameters`.
    // Vertex silently ignores an unknown `parameters.taskType`, which would
    // fall back to the model's default task type. This mirrors the Python SDK's
    // TextEmbeddingInput(text=..., task_type=...).
    return {
      content: text,
      task_type: taskType,
    };
  }

  async embed(
    text: string,
    memoryAction?: "add" | "update" | "search",
  ): Promise<number[]> {
    await this.initClient();
    if (!this.client || !this.helpers) {
      throw new Error("Client not initialized");
    }

    let embeddingType = "SEMANTIC_SIMILARITY";
    if (memoryAction !== undefined) {
      if (!(memoryAction in this.embeddingTypes)) {
        throw new Error(`Invalid memory action: ${memoryAction}`);
      }
      embeddingType = this.embeddingTypes[memoryAction];
    }

    const instance = this.formatInstance(text, embeddingType);
    const parameters = {
      outputDimensionality: this.embeddingDims,
    };

    const [response] = await this.client.predict({
      endpoint: this.endpoint(),
      instances: [this.helpers.toValue(instance) as any],

View on GitHub (pinned to 001c235229)

Solutions

  1. Do not override or stub initClient(); if you subclass, call super behavior or set client/helpers yourself
  2. Ensure a single copy of mem0ai/oss is loaded (check for duplicate node_modules)
  3. If it reproduces with stock code, report an issue with the SDK version and stack trace
Defensive patterns

Strategy: type-guard

Type guard

function isClientNotInitialized(err: unknown): boolean {
  return err instanceof Error && err.message === "Client not initialized";
}

Try / catch

catch (err) {
  if (err instanceof Error && err.message === "Client not initialized") {
    // Internal invariant: recreate the embedder instance and retry once
    embedder = new VertexAIEmbedder(cfg);
    return await embedder.embed(text);
  }
  throw err;
}

Prevention

When it happens

Trigger: 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().

Common situations: Custom forks of the SDK; test doubles that stub initClient; practically never seen in stock usage.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/96e8dcb82a2f1964. Report an issue: GitHub.