Behaviour for learning modules that extract knowledge from external sources.
Each learner implements this behaviour to provide a source of knowledge that can be automatically ingested into Recollect's memory.
Summary
Callbacks
Detect patterns across multiple events (optional).
Extract learnable content from an event.
Fetch new events/items to learn from since the last check.
Example implementation
Summarize a batch of events into synthesized memory entries (optional).
Types
Callbacks
Detect patterns across multiple events (optional).
Called with a batch of events to find cross-event patterns like migrations.
Returns
- List of pattern maps with :type, :events, :summary
Extract learnable content from an event.
Parameters
event- An event map from fetch_since
Returns
{:ok, extract}- Extract map with :content, :entry_type, :emotional_valence, :tags, :metadata{:skip, reason}- Skip this event (not learnable){:error, term}- Processing error
@callback fetch_since(since :: DateTime.t() | String.t(), scope_id :: binary()) :: {:ok, [map()]} | {:error, term()}
Fetch new events/items to learn from since the last check.
Parameters
since- DateTime or string (e.g., "2024-01-01")scope_id- The scope to learn for
Returns
{:ok, [event]}- List of events to process{:error, reason}- If fetching fails
@callback source() :: atom()
Example implementation:
defmodule MyApp.Learner.CI do
@behaviour Recollect.Learner
@impl true
def source, do: :ci
@impl true
def fetch_since(since, scope_id) do
# Fetch CI failures since the given date
end
@impl true
def extract(event) do
{:ok, %{
content: "CI Failure: #{event.failure_message}",
entry_type: :observation,
emotional_valence: :negative,
tags: ["ci", "failure", event.workflow],
metadata: %{source: :ci, job_id: event.id}
}}
end
endend
@doc """ Return the source name (e.g., :git, :terminal, :ci).
Summarize a batch of events into synthesized memory entries (optional).
Called after all individual events have been extracted. Allows learners to produce higher-level insights (e.g., commit grouping, deprecation events).
Returns
- List of extract maps (same shape as extract/1 return value)