LlmCore.Memory.Hindsight.WriteBuffer (llm_core v0.3.0)

Copy Markdown View Source

Write-behind buffer for Hindsight retain operations.

Features:

  • Buffers retain calls for batch sending
  • Sends batch every 5 seconds or at 50 items
  • Persists buffer to disk on shutdown
  • Restores buffer on startup
  • Retries failed batches with exponential backoff

This ensures retain operations don't block callers and reduces the number of requests to Hindsight.

Summary

Functions

Buffers a retain operation for batch sending. Returns immediately (non-blocking).

Returns the current buffer size.

Returns a specification to start this module under a supervisor.

Flushes the buffer immediately (blocking). Used before shutdown or by CLI command.

Starts the write buffer GenServer.

Types

state()

@type state() :: %{
  buffer: [map()],
  timer_ref: reference() | nil,
  retry_count: non_neg_integer()
}

Functions

buffer(content, metadata, opts \\ [])

@spec buffer(String.t(), map(), keyword()) :: :ok

Buffers a retain operation for batch sending. Returns immediately (non-blocking).

buffer_size()

@spec buffer_size() :: non_neg_integer()

Returns the current buffer size.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush()

@spec flush() :: :ok | {:error, term()}

Flushes the buffer immediately (blocking). Used before shutdown or by CLI command.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the write buffer GenServer.