RedaktAIDocs

Session Stores

Configure session persistence with MemoryStore, SQLiteStore, or RedisStore

Session stores persist the entity mappings that Rdakt AI uses for deanonymization. The choice of store depends on your deployment architecture.

MemoryStore (Default)

In-memory, thread-safe storage. Mappings are lost when the process restarts.

session:
  store: memory
from rdakt_ai import MemoryStore

store = MemoryStore()

Best for: Development, testing, single-request use cases, and serverless functions where sessions don't need to persist.

SQLiteStore

Persistent storage in a local SQLite database. Uses WAL mode for concurrent read performance.

session:
  store: sqlite
  path: /var/lib/rdakt/sessions.db
from rdakt_ai import SQLiteStore

store = SQLiteStore(path="sessions.db")
ParameterTypeDefaultDescription
pathstr"rdakt_sessions.db"Database file path

Best for: Single-server production deployments where sessions need to survive restarts.

RedisStore

Distributed storage using Redis. Supports TTL for automatic session expiry.

session:
  store: redis
  url: redis://localhost:6379
  ttl: 3600
  prefix: "rdakt:"
from rdakt_ai import RedisStore

store = RedisStore(
    url="redis://localhost:6379",
    ttl=3600,
    prefix="rdakt:",
)
ParameterTypeDefaultDescription
urlstr"redis://localhost:6379"Redis connection URL
ttlint | NoneNoneKey TTL in seconds (None = no expiry)
prefixstr"rdakt:"Key prefix for namespacing

Requires the redis extra:

pip install rdakt-ai[redis]

Best for: Multi-server deployments, microservices, or when you need session TTL.

Using a Store with Middleware

from rdakt_ai import RdaktMiddleware, SQLiteStore

store = SQLiteStore(path="sessions.db")

middleware = RdaktMiddleware(
    store=store,
    session_key="user-123",  # Isolate sessions per user
)

Using Config to Create a Store

from rdakt_ai import load_config, create_store, RdaktMiddleware

config = load_config("rdakt.yaml")
store = create_store(config)

middleware = RdaktMiddleware(config=config, store=store)

Context Manager

All stores support the context manager protocol for cleanup:

with SQLiteStore(path="sessions.db") as store:
    middleware = RdaktMiddleware(store=store)
    # ... use middleware ...
# store.close() called automatically

Custom Stores

Implement the SessionStore ABC:

from rdakt_ai import SessionStore

class MyStore(SessionStore):
    def save(self, session_id: str, mapping: dict[str, str]) -> None:
        # Persist mapping
        ...

    def load(self, session_id: str) -> dict[str, str] | None:
        # Return mapping or None if not found
        ...

    def delete(self, session_id: str) -> None:
        # Remove session data
        ...

On this page