Skip to content

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.

LangCrew Memory supports multiple storage providers:

  • ✅ Production-Ready: memory, sqlite, postgresql, mysql
  • ⚠️ Experimental: redis, mongodb

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

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

Scalable, production-ready database with full ACID compliance.

# PostgreSQL configuration
memory_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 variables
f"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 extensions
CREATE 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

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.

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.

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},
)
# Usage
memory_config = get_memory_config()
# Good: Environment variables
connection_string = os.getenv("DATABASE_URL")
# Bad: Hardcoded credentials
connection_string = "postgresql://admin:password123@localhost:5432/db"
# PostgreSQL with SSL
"postgresql://user:pass@localhost:5432/db?sslmode=require"
# MySQL with SSL
"mysql://user:pass@localhost:3306/db?ssl=true"
  • Verify database is running and accessible
  • Check connection string format
  • Ensure database permissions are correct
  • Verify the database file/connection is accessible
  • Monitor database resource usage
  • Optimize database indices if needed
  • Consider using PostgreSQL for production workloads with high concurrency