mem0ai/mem0 · error · Error
Provided Langchain 'client' does not appear to be a valid La
Error message
Provided Langchain 'client' does not appear to be a valid Langchain VectorStore (missing addVectors or similaritySearchVectorWithScore method).
What it means
The Langchain adapter duck-types the provided client: it requires addVectors and similaritySearchVectorWithScore to be functions, since those are the two methods the wrapper's insert and search depend on. If either is missing, the object is judged not to be a valid Langchain VectorStore and construction fails.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/langchain.ts:27
}
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 (
!this.dimension &&
(this.lcStore as any).embeddings?.embeddingDimension
) {
this.dimension = (this.lcStore as any).embeddings.embeddingDimension;
}
if (
!this.dimension &&
(this.lcStore as any).embedding?.embeddingDimension
) {View on GitHub (pinned to 001c235229)
Solutions
- Pass a genuine Langchain VectorStore subclass instance (MemoryVectorStore, FAISS, Chroma, PGVectorStore, etc.).
- If wrapping a custom store, implement addVectors(vectors, documents) and similaritySearchVectorWithScore(query, k) on it.
- Check the installed @langchain/community version's VectorStore interface for method renames.
Example fix
// before
new Memory({
vectorStore: { provider: 'langchain', config: { client: retriever } }, // wrong: retriever
});
// after
new Memory({
vectorStore: { provider: 'langchain', config: { client: new MemoryVectorStore(embeddings) } },
}); Defensive patterns
Strategy: type-guard
Validate before calling
const c: any = config.client;
if (typeof c?.addVectors !== 'function' ||
typeof c?.similaritySearchVectorWithScore !== 'function') {
throw new Error('client must be a Langchain VectorStore with addVectors and similaritySearchVectorWithScore');
} Type guard
interface LangchainVectorStoreLike {
addVectors(vectors: number[][], documents: any[]): Promise<void>;
similaritySearchVectorWithScore(query: number[], k: number): Promise<[any, number][]>;
delete?(opts: any): Promise<void>;
}
const isLangchainVectorStore = (c: unknown): c is LangchainVectorStoreLike =>
typeof c === 'object' && c !== null &&
typeof (c as any).addVectors === 'function' &&
typeof (c as any).similaritySearchVectorWithScore === 'function'; Prevention
- Pass real Langchain VectorStore subclass instances, not retrievers or ad-hoc objects.
- Custom stores must implement addVectors and similaritySearchVectorWithScore.
- Check the installed @langchain/community version for interface changes.
When it happens
Trigger: Passing an arbitrary object, a mock without the required methods, a partial adapter, or a Langchain retriever/embeddings object instead of a VectorStore instance as config.client.
Common situations: Wrapping a custom store that implements search but not addVectors; passing a Langchain Retriever (retrievers have getRelevantDocuments, not similaritySearchVectorWithScore); version drift where an @langchain/community store renames methods.
Related errors
- Langchain vector store provider requires an initialized Lang
- Langchain embedder provider requires an initialized Langchai
- Langchain provider requires an initialized Langchain instanc
- Provided Langchain 'instance' in the 'model' field does not
- IDs array must be provided and have the same length as vecto
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/f74a7d1c75f199bf.
Report an issue: GitHub.