Memory Storage

Database backends for agent memory and state persistence

Memory Storage

PraisonAI supports 22+ database backends for memory persistence. Choose the right one for your use case.

Storage Categories

Conversation Stores

Store conversation history and chat context. Best for session continuity.

State Stores

Store agent state, checkpoints, and runtime data. Best for complex workflows.

Quick Setup

python
from praisonaiagents import Agent

# SQLite (zero-config, default)
agent = Agent(memory=True)

# SQLite via preset
agent = Agent(memory="sqlite")

# MongoDB via URL scheme
agent = Agent(
    memory={
        "db": "mongodb://localhost:27017/mydb",
        "session_id": "user-123"
    }
)

Choosing a Database

Use CaseRecommendedWhy
Local developmentSQLite/JSONZero config
Production web appPostgreSQLReliable, scalable
High-speed cachingRedisSub-ms latency
ServerlessNeon/UpstashNo server management
AWS infrastructureDynamoDBNative integration
Decay-weighted recall across sessionsDakeraImportance-scored, time-decayed memory server

For self-hosted decay-weighted vector memory with importance scoring and tiered recall, see Dakera Memory.

Storage Backends

For training data, sessions, and general persistence, PraisonAI provides pluggable storage backends:

BackendDependenciesBest For
FileBackendNoneDevelopment, debugging
SQLiteBackendNoneProduction, concurrent access
RedisBackendredisHigh-speed caching, distributed
python
from praisonaiagents.storage import FileBackend, SQLiteBackend, RedisBackend

# File-based (default)
file_backend = FileBackend(storage_dir="~/.praisonai/data")

# SQLite (recommended for production)
sqlite_backend = SQLiteBackend(db_path="~/.praisonai/data.db")

# Redis (for distributed systems)
redis_backend = RedisBackend(url="redis://localhost:6379", prefix="praison:")

Durability

FileMemory writes are atomic. Every _write_json writes into a same-directory temp file, fsyncs it, then os.replaces it into place — a crash mid-write (SIGKILL, power loss, OOM) can never leave the memory file empty or half-written. Same guarantee on POSIX and Windows.

  • flock-based mutual exclusion still applies on Unix so concurrent writers see a consistent view (Windows has no flock; atomicity of os.replace still holds).
  • Temp files use a .<name>.…tmp prefix inside the memory directory. A crash between temp creation and rename leaves the temp file behind; it is safe to delete manually and is otherwise harmless.

See Storage Backends for detailed usage with all components.

Related