> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<CardGroup cols={3}>
  <Card title="PostgreSQL" icon="elephant" href="/docs/databases/postgres">
    Production-ready relational DB
  </Card>

  <Card title="MySQL" icon="database" href="/docs/databases/mysql">
    Popular relational DB
  </Card>

  <Card title="SQLite" icon="file" href="/docs/databases/sqlite">
    Zero-config local storage
  </Card>

  <Card title="JSON" icon="brackets-curly" href="/docs/databases/json">
    Simple file-based storage
  </Card>

  <Card title="Supabase" icon="bolt" href="/docs/databases/supabase">
    Managed Postgres
  </Card>

  <Card title="Neon" icon="cloud" href="/docs/databases/neon">
    Serverless Postgres
  </Card>
</CardGroup>

### State Stores

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

<CardGroup cols={3}>
  <Card title="Redis" icon="bolt" href="/docs/databases/redis">
    High-speed caching
  </Card>

  <Card title="MongoDB" icon="leaf" href="/docs/databases/mongodb">
    Document store
  </Card>

  <Card title="DynamoDB" icon="aws" href="/docs/databases/dynamodb">
    AWS managed
  </Card>

  <Card title="Firestore" icon="google" href="/docs/databases/firestore">
    Google Cloud
  </Card>

  <Card title="Upstash" icon="cloud" href="/docs/databases/upstash">
    Serverless Redis
  </Card>

  <Card title="Dakera" icon="brain" href="/docs/features/dakera-memory">
    Decay-weighted vector recall
  </Card>
</CardGroup>

## Quick Setup

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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"
    }
)
```

<Note>
  `memory=` presets and URL schemes accept only shipped memory adapters. Presets: `chroma`, `dakera`, `file`, `in_memory`, `mem0`, `mongodb`, `sqlite`. URL schemes: `sqlite://`, `mongodb://`, `mongodb+srv://`. Values like `memory="redis"` or `memory={"backend": "redis"}` raise `ValueError`. For Redis/Postgres *state* persistence, use the storage backends below or `db(state_url="redis://…")`.
</Note>

## Choosing a Database

| Use Case                              | Recommended  | Why                                           |
| ------------------------------------- | ------------ | --------------------------------------------- |
| Local development                     | SQLite/JSON  | Zero config                                   |
| Production web app                    | PostgreSQL   | Reliable, scalable                            |
| High-speed caching                    | Redis        | Sub-ms latency                                |
| Serverless                            | Neon/Upstash | No server management                          |
| AWS infrastructure                    | DynamoDB     | Native integration                            |
| Decay-weighted recall across sessions | Dakera       | Importance-scored, time-decayed memory server |

For self-hosted decay-weighted vector memory with importance scoring and tiered recall, see [Dakera Memory](/docs/features/dakera-memory).

## Storage Backends

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

| Backend           | Dependencies | Best For                        |
| ----------------- | ------------ | ------------------------------- |
| **FileBackend**   | None         | Development, debugging          |
| **SQLiteBackend** | None         | Production, concurrent access   |
| **RedisBackend**  | `redis`      | High-speed caching, distributed |

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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:")
```

<Note>
  FileMemory sanitises `user_id` before using it as a directory name — values containing path separators, `..`, or other unsafe characters fall back to `"default"`. This prevents accidental writes outside the configured memory directory.
</Note>

### Durability

`FileMemory` writes are atomic. Every `_write_json` writes into a same-directory temp file, `fsync`s it, then `os.replace`s 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](/docs/storage/backends) for detailed usage with all components.

## Related

<CardGroup cols={2}>
  <Card title="Database Overview" icon="database" href="/docs/databases/overview">
    Complete database reference
  </Card>

  <Card title="Session Resume" icon="rotate" href="/docs/persistence/session-resume">
    Continue conversations
  </Card>

  <Card title="Storage Backends" icon="hard-drive" href="/docs/storage/backends">
    Pluggable storage backends
  </Card>

  <Card title="Dakera Memory" icon="brain" href="/docs/features/dakera-memory">
    Self-hosted decay-weighted vector memory
  </Card>
</CardGroup>
