withDataSource

Configures the data source that feeds user interaction events into the learning system.

The data source acts as the bridge between your application's user interface and KARL's learning engine. It captures meaningful user interactions and converts them into standardized InteractionData objects that the learning engine can process.

Data source responsibilities:

  • Event capture: Monitor user actions, UI interactions, and system events

  • Data transformation: Convert application events to standardized format

  • Event filtering: Exclude noise and focus on learning-relevant interactions

  • Rate limiting: Prevent overwhelming the learning engine with excessive data

  • Privacy filtering: Ensure sensitive data is excluded or anonymized

Common interaction types to capture:

  • UI events: Button clicks, menu selections, navigation patterns

  • Content interactions: Document views, search queries, item selections

  • Temporal patterns: Session duration, time-of-day usage, frequency patterns

  • Context data: Application state, user preferences, environmental factors

  • Performance metrics: Task completion time, error rates, success indicators

Implementation patterns:

class MyAppDataSource : DataSource {
override fun observeInteractionData(
onNewData: suspend (InteractionData) -> Unit,
coroutineScope: CoroutineScope
): Job {
return coroutineScope.launch {
// Collect UI events and convert to InteractionData
uiEventFlow.collect { event ->
val interaction = InteractionData(
type = event.type,
details = event.toDetails(),
timestamp = System.currentTimeMillis(),
userId = currentUserId
)
onNewData(interaction)
}
}
}
}

Data quality considerations:

  • Ensure consistent data format across different interaction types

  • Include sufficient context for meaningful pattern recognition

  • Balance detail level with privacy and performance requirements

  • Implement proper error handling for data conversion failures

Privacy and security:

  • Never capture sensitive user data (passwords, personal information)

  • Implement data anonymization for identification-sensitive interactions

  • Provide user controls for disabling data collection

  • Ensure compliance with applicable privacy regulations

Return

This builder instance for method chaining.

Parameters

source

Your application's implementation of the DataSource interface that captures and standardizes user interaction events for learning.

See also

for detailed interface documentation

InteractionData

for data format specifications

Throws

IllegalArgumentException

if source is null