Storage Configuration
LangCrew Memory supports multiple storage providers for both short-term and long-term memory. Choose the appropriate provider based on your deployment environment and scalability needs.
Overview
Section titled “Overview”LangCrew Memory supports multiple storage providers:
- ✅ Production-Ready:
memory,sqlite,postgresql,mysql - ⚠️ Experimental:
redis,mongodb
Storage Providers
Section titled “Storage Providers”In-Memory Storage
Section titled “In-Memory Storage”Fast, ephemeral storage for development and testing. No persistence across restarts.
from langcrew.memory import MemoryConfig
memory_config = MemoryConfig( provider="memory", # No persistence short_term={"enabled": True}, long_term={"enabled": True},)Characteristics:
- Speed: Fastest
- Persistence: None (lost on restart)
- Best for: Development, testing, ephemeral sessions
SQLite
Section titled “SQLite”File-based database ideal for single-user applications and development.
memory_config = MemoryConfig( provider="sqlite", connection_string="sqlite:///memory.db", short_term={"enabled": True}, long_term={"enabled": True},)Connection String Examples:
# Relative path"sqlite:///memory.db"
# Absolute path"sqlite:////var/data/memory.db"
# In-memory SQLite (testing only)"sqlite:///:memory:"Characteristics:
- Speed: Fast
- Persistence: File-based
- Best for: Single-user apps, development, local deployments
PostgreSQL
Section titled “PostgreSQL”Scalable, production-ready database with full ACID compliance.
# PostgreSQL configurationmemory_config = MemoryConfig( provider="postgresql", connection_string="postgresql://user:password@localhost:5432/memory_db", short_term={"enabled": True}, long_term={"enabled": True},)Connection String Examples:
# Basic connection"postgresql://user:password@localhost:5432/database"
# With specific schema"postgresql://user:password@localhost:5432/database?schema=memory"
# With connection pooling"postgresql://user:password@localhost:5432/database"
# Using environment variablesf"postgresql://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_HOST')}:5432/{os.getenv('DB_NAME')}"Characteristics:
- Speed: Good (network-dependent)
- Persistence: Durable, ACID-compliant
- Best for: Production, multi-user applications, scalable deployments
Required Setup:
-- PostgreSQL requires specific extensionsCREATE EXTENSION IF NOT EXISTS vector;CREATE EXTENSION IF NOT EXISTS hstore;Production-ready relational database with wide adoption.
memory_config = MemoryConfig( provider="mysql", connection_string="mysql://user:password@localhost:3306/memory_db", short_term={"enabled": True}, long_term={"enabled": True},)Characteristics:
- Speed: Good (network-dependent)
- Persistence: Durable
- Best for: Production, existing MySQL infrastructure
Redis (⚠️ Experimental)
Section titled “Redis (⚠️ Experimental)”High-performance in-memory data store with optional persistence.
memory_config = MemoryConfig( provider="redis", connection_string="redis://localhost:6379/0", short_term={"enabled": True}, long_term={"enabled": True},)Connection String Examples:
# Basic Redis connection"redis://localhost:6379/0"
# Redis with authentication"redis://:password@localhost:6379/0"
# Redis with custom database"redis://localhost:6379/2"⚠️ Status: Experimental - not fully tested in production environments.
MongoDB (⚠️ Experimental)
Section titled “MongoDB (⚠️ Experimental)”Document-oriented NoSQL database.
memory_config = MemoryConfig( provider="mongodb", connection_string="mongodb://localhost:27017/memory_db", short_term={"enabled": True}, long_term={"enabled": True},)⚠️ Status: Experimental - not fully tested in production environments.
Environment-based Configuration
Section titled “Environment-based Configuration”Configure different storage providers for different environments:
import os
def get_memory_config(): env = os.getenv("ENVIRONMENT", "development")
if env == "production": return MemoryConfig( provider="postgresql", connection_string=os.getenv("DATABASE_URL"), short_term={"enabled": True}, long_term={"enabled": True}, ) elif env == "staging": return MemoryConfig( provider="postgresql", connection_string="postgresql://staging_user:pass@staging-db:5432/memory_staging", short_term={"enabled": True}, long_term={"enabled": True}, ) else: # development return MemoryConfig( provider="sqlite", connection_string="sqlite:///dev_memory.db", short_term={"enabled": True}, long_term={"enabled": True}, )
# Usagememory_config = get_memory_config()Security Best Practices
Section titled “Security Best Practices”Use Environment Variables
Section titled “Use Environment Variables”# Good: Environment variablesconnection_string = os.getenv("DATABASE_URL")
# Bad: Hardcoded credentialsconnection_string = "postgresql://admin:password123@localhost:5432/db"Secure Connection Strings
Section titled “Secure Connection Strings”# PostgreSQL with SSL"postgresql://user:pass@localhost:5432/db?sslmode=require"
# MySQL with SSL"mysql://user:pass@localhost:3306/db?ssl=true"Troubleshooting
Section titled “Troubleshooting”Connection Failures
Section titled “Connection Failures”- Verify database is running and accessible
- Check connection string format
- Ensure database permissions are correct
- Verify the database file/connection is accessible
Performance Issues
Section titled “Performance Issues”- Monitor database resource usage
- Optimize database indices if needed
- Consider using PostgreSQL for production workloads with high concurrency
Next Steps
Section titled “Next Steps”- Short-term Memory - Configure conversation history
- Long-term Memory - Configure persistent knowledge
- Memory Concepts - Understand memory architecture