mem0ai/mem0 · error · Error

Langchain vector store provider requires an initialized Lang

Error message

Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field.

What it means

The Langchain vector store adapter requires you to supply an already-initialized Langchain VectorStore instance in the client config field; it is a wrapper, not a factory. The constructor throws immediately when client is missing, null, or not an object.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/langchain.ts:18

import type { VectorStore as LangchainVectorStoreInterface } from "@langchain/core/vectorstores";
import { VectorStore } from "./base"; // mem0's VectorStore interface
import { SearchFilters, VectorStoreConfig, VectorStoreResult } from "../types";

// Config specifically for the Langchain wrapper
interface LangchainStoreConfig extends VectorStoreConfig {
  client: LangchainVectorStoreInterface;
  // dimension might still be useful for validation if not automatically inferred
}

export class LangchainVectorStore implements VectorStore {
  private lcStore: LangchainVectorStoreInterface;
  private dimension?: number;
  private storeUserId: string = "anonymous-langchain-user"; // Simple in-memory user ID

  constructor(config: LangchainStoreConfig) {
    if (!config.client || typeof config.client !== "object") {
      throw new Error(
        "Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field.",
      );
    }
    // Basic checks for core methods
    if (
      typeof config.client.addVectors !== "function" ||
      typeof config.client.similaritySearchVectorWithScore !== "function"
    ) {
      throw new Error(
        "Provided Langchain 'client' does not appear to be a valid Langchain VectorStore (missing addVectors or similaritySearchVectorWithScore method).",
      );
    }

    this.lcStore = config.client;
    this.dimension = config.dimension;

    // Attempt to get dimension from the underlying store if not provided
    if (

View on GitHub (pinned to 001c235229)

Solutions

  1. Instantiate your Langchain store first (e.g. new MemoryVectorStore(embeddings) or new FAISS(embeddings)), then pass it as client.
  2. Check for null/undefined before constructing if the store is created conditionally.
  3. Pass config.dimension explicitly if the store cannot infer it.

Example fix

// before
new Memory({
  vectorStore: { provider: 'langchain', config: {} },
});

// after
import { MemoryVectorStore } from '@langchain/community/vectorstores/memory';
const lcStore = new MemoryVectorStore(embeddings);
new Memory({
  vectorStore: { provider: 'langchain', config: { client: lcStore } },
});
Defensive patterns

Strategy: type-guard

Validate before calling

if (!config?.client || typeof config.client !== 'object') {
  throw new Error('Instantiate the Langchain VectorStore first, then pass it as config.client');
}

Type guard

const isObjectClient = (c: unknown): c is object =>
  typeof c === 'object' && c !== null;

Prevention

When it happens

Trigger: Constructing LangchainVectorStore (via Memory config vectorStore.provider='langchain') with config that omits client, sets client: null/undefined, or passes a class constructor instead of an instance.

Common situations: Following config patterns of other providers (qdrant, chroma) that take a URL/connection string instead of a client instance; forgetting that langchain is a BYO-store provider; passing an uninitialized import.

Related errors


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