How to Configure Mem0 to Use a Custom Vector Store (Pinecone or Qdrant)
To configure Mem0 with a custom vector store, set the provider field in your MemoryConfig to "pinecone" or "qdrant" and supply the provider-specific configuration parameters; Mem0's VectorStoreFactory automatically instantiates the correct backend.
Mem0 is an open-source memory layer for LLM applications that abstracts vector database interactions through a unified interface. Whether you need the serverless scalability of Pinecone or the on-premise flexibility of Qdrant, configuring a custom vector store requires understanding the factory pattern and Pydantic configuration classes used throughout the codebase.
Understanding the Vector Store Architecture
Mem0 decouples the memory logic from storage implementation through a factory pattern. This allows you to swap vector databases without changing your application code.
The VectorStoreFactory Pattern
The VectorStoreFactory in mem0/utils/factory.py maintains a mapping between provider names and concrete implementation classes. When you initialize a Memory instance, the factory reads config.vector_store.provider and returns the appropriate class:
"pinecone"→mem0.vector_stores.pinecone.PineconeDB"qdrant"→mem0.vector_stores.qdrant.Qdrant
The Memory.__init__ method in mem0/memory/main.py calls VectorStoreFactory.create with the processed configuration, ensuring the vector store is ready before any memory operations occur.
Configuration Validation with Pydantic
Each vector store has a dedicated Pydantic configuration class that validates required fields at instantiation:
PineconeConfig(mem0/configs/vector_stores/pinecone.py) validatesapi_key,environment,serverless_config, andcollection_nameQdrantConfig(mem0/configs/vector_stores/qdrant.py) validates connection parameters includinghost,port,path, orurl
These validators ensure that missing or incompatible settings raise immediate errors during startup rather than at query time.
Configuring Pinecone as Your Vector Store
Pinecone provides managed, serverless vector search with metadata filtering. To use it with Mem0, you must configure both the connection parameters and the index settings.
Required Configuration Parameters
The PineconeConfig class requires the following fields:
collection_name: The name of your Pinecone indexembedding_model_dims: Dimensionality of your embeddings (e.g., 1536 for OpenAI)api_key: Your Pinecone API key (or setPINECONE_API_KEYenvironment variable)environment: Pinecone environment identifier (e.g.,"us-west1-gcp")serverless_config: Dictionary withcloud(e.g.,"aws") andregion(e.g.,"us-east-1") for serverless indexesmetric: Distance metric (e.g.,"cosine","euclidean")batch_size: Number of vectors to upsert in batches (default 100)
Python Implementation Example
from mem0 import Memory
from mem0.configs.base import MemoryConfig
# Configure Pinecone vector store
pinecone_config = {
"provider": "pinecone",
"config": {
"collection_name": "mem0_conversations",
"embedding_model_dims": 1536,
"api_key": "YOUR_PINECONE_API_KEY",
"environment": "us-west1-gcp",
"serverless_config": {
"cloud": "aws",
"region": "us-east-1"
},
"metric": "cosine",
"batch_size": 200
}
}
# Initialize Mem0 with Pinecone backend
memory = Memory(MemoryConfig(vector_store=pinecone_config))
# Use Mem0 normally
memory.add(
messages=[{"role": "user", "content": "I prefer Python for data science"}],
user_id="user123"
)
Configuring Qdrant as Your Vector Store
Qdrant offers both local storage and distributed deployment options. Mem0 supports Qdrant through the Qdrant class in mem0/vector_stores/qdrant.py.
Connection Modes and Settings
The QdrantConfig class supports three connection modes:
-
Host and Port: Connect to a running Qdrant server
host: Server hostname (e.g.,"localhost")port: Server port (e.g.,6333)api_key: Optional authentication key
-
URL: Connect via full URL string
url: Complete connection string (e.g.,"http://localhost:6333")
-
Local Path: Run Qdrant in embedded mode
path: Local directory for storage (e.g.,"./qdrant_storage")
Common configuration fields include:
collection_name: Name of the Qdrant collectionembedding_model_dims: Vector dimensionalitymetric: Distance metric ("cosine","euclidean", or"dot")on_disk: Boolean to store vectors on disk rather than memory
Python Implementation Example
from mem0 import Memory
from mem0.configs.base import MemoryConfig
# Configure Qdrant vector store (local mode)
qdrant_config = {
"provider": "qdrant",
"config": {
"collection_name": "mem0_local",
"embedding_model_dims": 1536,
"path": "./qdrant_data", # Local storage path
"metric": "cosine",
"on_disk": False
}
}
# Or configure for remote Qdrant server
qdrant_server_config = {
"provider": "qdrant",
"config": {
"collection_name": "mem0_production",
"embedding_model_dims": 1536,
"host": "qdrant.example.com",
"port": 6333,
"api_key": "YOUR_QDRANT_API_KEY",
"metric": "cosine"
}
}
# Initialize Mem0
memory = Memory(MemoryConfig(vector_store=qdrant_config))
# Add and search memories
memory.add(
messages=[{"role": "assistant", "content": "The user enjoys hiking in the Alps"}],
user_id="alice"
)
results = memory.search(
query="outdoor activities",
user_id="alice",
limit=3
)
Loading Configuration from Files and Environment Variables
Mem0 supports flexible configuration loading beyond Python dictionaries, allowing you to externalize settings for different deployment environments.
YAML and JSON Configuration Files
You can define your vector store configuration in YAML or JSON files and load them at runtime. The structure mirrors the Python dictionary format exactly.
# config.yaml
vector_store:
provider: pinecone
config:
collection_name: mem0_production
embedding_model_dims: 1536
api_key: ${PINECONE_API_KEY} # Environment variable substitution
environment: us-east-1-aws
serverless_config:
cloud: aws
region: us-east-1
metric: cosine
batch_size: 100
import yaml
from mem0 import Memory
from mem0.configs.base import MemoryConfig
with open("config.yaml") as f:
config_dict = yaml.safe_load(f)
memory = Memory(MemoryConfig(**config_dict))
Environment Variable Overrides
Mem0's Pydantic configuration classes automatically read from environment variables using standard naming conventions. This allows sensitive credentials like API keys to stay out of your codebase.
For Pinecone:
PINECONE_API_KEY– Automatically mapped to theapi_keyfieldPINECONE_ENVIRONMENT– Maps toenvironment
For Qdrant:
QDRANT_API_KEY– Authentication key for remote serversQDRANT_HOST– Server hostname
You can also use the MEM0_ prefix for general Mem0 settings:
export MEM0_VECTOR_STORE_PROVIDER=qdrant
export MEM0_VECTOR_STORE_COLLECTION_NAME=mem0_env_collection
export MEM0_VECTOR_STORE_EMBEDDING_MODEL_DIMS=1536
from mem0 import Memory
# Configuration loaded automatically from environment variables
memory = Memory()
Summary
Configuring Mem0 to use a custom vector store involves understanding the factory-based architecture that decouples memory logic from storage implementation:
- Use the
providerfield inMemoryConfig.vector_storeto select"pinecone"or"qdrant" - Supply provider-specific configurations through
PineconeConfigorQdrantConfig, which validate required fields like API keys, hosts, and collection names - Leverage the VectorStoreFactory in
mem0/utils/factory.pyto automatically instantiate the correct backend class based on your configuration - Externalize sensitive credentials using environment variables that Pydantic config classes automatically detect
The unified interface in mem0/memory/main.py ensures that once configured, all vector stores expose the same add(), search(), and get() methods regardless of the underlying database.
Frequently Asked Questions
What vector stores does Mem0 support besides Pinecone and Qdrant?
Mem0 supports multiple vector stores including Chroma, PGVector, Milvus, and Redis, in addition to Pinecone and Qdrant. Each provider follows the same factory pattern in mem0/utils/factory.py, requiring a config class in mem0/configs/vector_stores/ and an implementation class in mem0/vector_stores/. You can check the factory mapping to see the complete list of supported providers.
How do I switch from one vector store to another without losing data?
Switching vector stores requires migrating your vector data since each store uses different storage formats and indexing structures. Mem0 does not provide automatic migration tools between different vector databases. To switch, you must export your data from the current store (using the store's native export tools), transform the vectors and metadata into the format expected by the new store, and then ingest them into the new collection configured in your MemoryConfig.
Can I use a local vector store for development and a cloud provider for production?
Yes, this is a common pattern supported by Mem0's configuration system. For local development, configure Qdrant with the path parameter to use embedded mode (path: "./qdrant_data"), or use Chroma with a local directory. For production, switch to Pinecone or a remote Qdrant server by updating the host, port, and api_key fields. Use environment variables to toggle between configurations without code changes, or maintain separate YAML config files for each environment.
What happens if I omit required configuration fields for Pinecone or Qdrant?
Mem0 uses Pydantic models (PineconeConfig and QdrantConfig) that validate configuration at instantiation. If you omit required fields like api_key for Pinecone or collection_name for either provider, Pydantic raises a validation error immediately when creating the Memory instance. This prevents runtime failures during vector operations. To avoid these errors, ensure all mandatory fields are provided in your config dictionary, YAML file, or as environment variables that the Pydantic models can automatically detect.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →