withDataStorage

Configures the data storage implementation for persistent state and interaction history.

The data storage component handles all persistence operations including:

  • Container state: Serialized AI model weights, parameters, and configuration

  • Interaction history: Timestamped user interactions for replay and analysis

  • User preferences: Instructions, settings, and customization data

  • Performance metrics: Learning statistics and model evaluation data

  • Data migration: Schema updates and backward compatibility handling

Storage implementations must guarantee:

  • Data isolation: Complete separation between different user accounts

  • Thread safety: Concurrent access from multiple coroutines

  • Atomic operations: Consistent state even during application crashes

  • Encryption: Sensitive data protection using appropriate crypto standards

  • Efficient queries: Fast retrieval for real-time prediction scenarios

Common implementations:

  • RoomDataStorage: Android Room database with SQLite backend

  • SQLDelightStorage: Cross-platform SQL database abstraction

  • InMemoryStorage: Volatile storage for testing and development

  • EncryptedFileStorage: File-based storage with automatic encryption

Performance considerations:

  • Choose storage based on expected data volume and query patterns

  • Configure appropriate indexing for frequently accessed data

  • Implement data cleanup policies to prevent unbounded growth

  • Consider backup and restore capabilities for user data migration

Security considerations:

  • All user data must be encrypted at rest using industry standards

  • Implement proper key management and rotation policies

  • Ensure compliance with data protection regulations (GDPR, CCPA)

  • Provide user controls for data export and deletion

Return

This builder instance for method chaining.

Parameters

storage

A fully configured DataStorage instance that provides persistent storage capabilities with proper encryption and isolation guarantees.

See also

for detailed interface documentation

com.karl.room.RoomDataStorage

for Room database implementation

com.karl.sqldelight.SQLDelightStorage

for cross-platform SQL implementation

Throws

IllegalArgumentException

if storage is null or not properly configured