# `LlmCore.Memory.Hindsight.WriteBuffer`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/memory/hindsight/write_buffer.ex#L1)

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.

# `state`

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

# `buffer`

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

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

# `buffer_size`

```elixir
@spec buffer_size() :: non_neg_integer()
```

Returns the current buffer size.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `flush`

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

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

# `start_link`

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

Starts the write buffer GenServer.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
