{"record":{"id":"bdb40c154981b0c6","repo":"mem0ai/mem0","slug":"langchain-vector-store-provider-requires-an-initia","errorCode":null,"errorMessage":"Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field.","messagePattern":"Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/langchain.ts","lineNumber":18,"sourceCode":"import type { VectorStore as LangchainVectorStoreInterface } from \"@langchain/core/vectorstores\";\nimport { VectorStore } from \"./base\"; // mem0's VectorStore interface\nimport { SearchFilters, VectorStoreConfig, VectorStoreResult } from \"../types\";\n\n// Config specifically for the Langchain wrapper\ninterface LangchainStoreConfig extends VectorStoreConfig {\n  client: LangchainVectorStoreInterface;\n  // dimension might still be useful for validation if not automatically inferred\n}\n\nexport class LangchainVectorStore implements VectorStore {\n  private lcStore: LangchainVectorStoreInterface;\n  private dimension?: number;\n  private storeUserId: string = \"anonymous-langchain-user\"; // Simple in-memory user ID\n\n  constructor(config: LangchainStoreConfig) {\n    if (!config.client || typeof config.client !== \"object\") {\n      throw new Error(\n        \"Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field.\",\n      );\n    }\n    // Basic checks for core methods\n    if (\n      typeof config.client.addVectors !== \"function\" ||\n      typeof config.client.similaritySearchVectorWithScore !== \"function\"\n    ) {\n      throw new Error(\n        \"Provided Langchain 'client' does not appear to be a valid Langchain VectorStore (missing addVectors or similaritySearchVectorWithScore method).\",\n      );\n    }\n\n    this.lcStore = config.client;\n    this.dimension = config.dimension;\n\n    // Attempt to get dimension from the underlying store if not provided\n    if (","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/langchain.ts#L1-L36","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Instantiate your Langchain store first (e.g. new MemoryVectorStore(embeddings) or new FAISS(embeddings)), then pass it as client.","Check for null/undefined before constructing if the store is created conditionally.","Pass config.dimension explicitly if the store cannot infer it."],"exampleFix":"// before\nnew Memory({\n  vectorStore: { provider: 'langchain', config: {} },\n});\n\n// after\nimport { MemoryVectorStore } from '@langchain/community/vectorstores/memory';\nconst lcStore = new MemoryVectorStore(embeddings);\nnew Memory({\n  vectorStore: { provider: 'langchain', config: { client: lcStore } },\n});","handlingStrategy":"type-guard","validationCode":"if (!config?.client || typeof config.client !== 'object') {\n  throw new Error('Instantiate the Langchain VectorStore first, then pass it as config.client');\n}","typeGuard":"const isObjectClient = (c: unknown): c is object =>\n  typeof c === 'object' && c !== null;","tryCatchPattern":null,"preventionTips":["Remember the langchain provider is BYO-store: construct the Langchain store first.","Fail fast on missing client during app config validation, before creating Memory."],"tags":["langchain","config","vector-store","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}