docs/components/vectordbs/dbs/langchain.mdx
Mem0 supports LangChain as a provider for vector store integration. LangChain provides a unified interface to various vector databases, making it easy to integrate different vector store providers through a consistent API.
<Note> When using LangChain as your vector store provider, you must set the collection name to "mem0". This is a required configuration for proper integration with Mem0. </Note>embeddings = OpenAIEmbeddings() vector_store = Chroma( persist_directory="./chroma_db", embedding_function=embeddings, collection_name="mem0" # Required collection name )
config = { "vector_store": { "provider": "langchain", "config": { "client": vector_store } } }
m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="alice", metadata={"category": "movies"})
```typescript TypeScript
import { Memory } from "mem0ai";
import { OpenAIEmbeddings } from "@langchain/openai";
import { MemoryVectorStore as LangchainMemoryStore } from "langchain/vectorstores/memory";
const embeddings = new OpenAIEmbeddings();
const vectorStore = new LangchainVectorStore(embeddings);
const config = {
"vector_store": {
"provider": "langchain",
"config": { "client": vectorStore }
}
}
const memory = new Memory(config);
const messages = [
{ role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" },
{ role: "assistant", content: "How about thriller movies? They can be quite engaging." },
{ role: "user", content: "I'm not a big fan of thriller movies but I love sci-fi movies." },
{ role: "assistant", content: "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future." }
]
await memory.add(messages, { userId: "alice", metadata: { category: "movies" } });
LangChain supports a wide range of vector store providers, including:
You can use any of these vector store instances directly in your configuration. For a complete and up-to-date list of available providers, refer to the LangChain Vector Stores documentation.
When using LangChain as a vector store provider, there are some limitations to be aware of:
Bulk Operations: The get_all and delete_all operations are not supported when using LangChain as the vector store provider. This is because LangChain's vector store interface doesn't provide standardized methods for these bulk operations across all providers.
Provider-Specific Features: Some advanced features may not be available depending on the specific vector store implementation you're using through LangChain.
When using LangChain as a vector store provider, you'll need to:
All available parameters for the langchain vector store config are present in Master List of All Params in Config.