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
- 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
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
- 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
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
- Failed to parse googleServiceAccountJson: ${err.message}
- Vertex AI could not determine a Google Cloud project ID. Set
- Invalid memory action: ${memoryAction}
- No predictions returned from Vertex AI
- Failed to extract embedding values from response
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/96e8dcb82a2f1964.
Report an issue: GitHub.