mem0ai/mem0 · error · Error

Langchain embedder provider requires an initialized Langchai

Error message

Langchain embedder provider requires an initialized Langchain Embeddings instance passed via the 'model' field in the embedder config.

What it means

Thrown by the LangchainEmbedder constructor when config.model is not an object. This provider is special: instead of a model name string, the 'model' field must be an already-initialized LangChain Embeddings instance (e.g. new OpenAIEmbeddings()), which the SDK delegates to via embedQuery/embedDocuments. A string, number, undefined, or array fails this check.

Source

Thrown at mem0-ts/src/oss/src/embeddings/langchain.ts:12

import type { Embeddings } from "@langchain/core/embeddings";
import { Embedder } from "./base";
import { EmbeddingConfig } from "../types";

export class LangchainEmbedder implements Embedder {
  private embedderInstance: Embeddings;
  private batchSize?: number; // Some LC embedders have batch size

  constructor(config: EmbeddingConfig) {
    // Check if config.model is provided and is an object (the instance)
    if (!config.model || typeof config.model !== "object") {
      throw new Error(
        "Langchain embedder provider requires an initialized Langchain Embeddings instance passed via the 'model' field in the embedder config.",
      );
    }
    // Basic check for embedding methods
    if (
      typeof (config.model as any).embedQuery !== "function" ||
      typeof (config.model as any).embedDocuments !== "function"
    ) {
      throw new Error(
        "Provided Langchain 'instance' in the 'model' field does not appear to be a valid Langchain Embeddings instance (missing embedQuery or embedDocuments method).",
      );
    }
    this.embedderInstance = config.model as Embeddings;
    // Store batch size if the instance has it (optional)
    this.batchSize = (this.embedderInstance as any).batchSize;
  }

  async embed(text: string): Promise<number[]> {

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass an instantiated LangChain Embeddings object: config: { model: new OpenAIEmbeddings({ apiKey }) }
  2. Make sure it is `new ...`, not the class reference
  3. Confirm @langchain/core is installed at a compatible version and the instance is created before Memory construction

Example fix

// before
embedder: { provider: 'langchain', config: { model: 'text-embedding-3-small' } }

// after
import { OpenAIEmbeddings } from '@langchain/openai';
embedder: { provider: 'langchain', config: { model: new OpenAIEmbeddings() } }
Defensive patterns

Strategy: type-guard

Validate before calling

if (!embeddingsInstance || typeof embeddingsInstance !== 'object') {
  throw new Error("Pass a LangChain Embeddings instance in config.model, e.g. new OpenAIEmbeddings()");
}

Type guard

import type { Embeddings } from '@langchain/core/embeddings';
const isLangchainEmbeddings = (m: unknown): m is Embeddings =>
  !!m && typeof m === 'object' &&
  typeof (m as Embeddings).embedQuery === 'function' &&
  typeof (m as Embeddings).embedDocuments === 'function';

Prevention

When it happens

Trigger: embedder: { provider: 'langchain', config: { model: 'text-embedding-3-small' } } — passing a model name like other providers; passing the class itself (OpenAIEmbeddings) instead of an instance (new OpenAIEmbeddings()); forgetting the config entirely.

Common situations: Copying the OpenAI embedder config shape and just switching provider to 'langchain'; bundling for the browser where the instance serializes oddly; passing an instance created in a different package version with an incompatible shape.

Related errors


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