PhoenixAI.Store.Memory.Pipeline (PhoenixAI.Store v0.1.0)

Copy Markdown View Source

Orchestrates memory strategy execution for a conversation's message list.

The pipeline:

  1. Extracts pinned messages (role: :system or pinned: true)
  2. Sorts strategies by priority (lower = runs first)
  3. Applies each strategy sequentially on non-pinned messages
  4. Re-injects pinned messages at the beginning (in original order)
  5. Returns {:ok, filtered_messages}

Presets

Pipeline.preset(:default)     # SlidingWindow last: 50
Pipeline.preset(:aggressive)  # TokenTruncation max_tokens: 4096
Pipeline.preset(:summarize)   # Summarization + SlidingWindow

Note on pinned message ordering: Pinned messages (role: :system or pinned: true) are always placed at the beginning of the output list, regardless of their original position. This is intentional — LLMs expect system instructions at the start of the message list. If you need a pinned message at a specific position, consider injecting it manually after the pipeline runs.

Summary

Functions

Creates a new pipeline from a list of {strategy_module, opts} tuples.

Returns a preset pipeline configuration.

Runs the pipeline against a list of messages.

Types

strategy_entry()

@type strategy_entry() :: {module(), keyword()}

t()

@type t() :: %PhoenixAI.Store.Memory.Pipeline{strategies: [strategy_entry()]}

Functions

new(strategies)

@spec new([strategy_entry()]) :: t()

Creates a new pipeline from a list of {strategy_module, opts} tuples.

preset(atom)

@spec preset(:default | :aggressive | :summarize) :: t()

Returns a preset pipeline configuration.

run(pipeline, messages, context, opts \\ [])

@spec run(t(), [map()], map(), keyword()) :: {:ok, [map()]} | {:error, term()}

Runs the pipeline against a list of messages.

Pinned messages (system messages and messages with pinned: true) are extracted before strategies run and re-injected at the beginning of the result in their original order.