record method

void record(
  1. EmbeddingModel model,
  2. ActiveEmbedderParams params
)

Records a freshly built model and what it was built from.

Implementation

void record(EmbeddingModel model, ActiveEmbedderParams params) {
  // Listener first, cache second. `addCloseListener` is abstract on the
  // published interface, not inherited from `CloseNotifier`, so a third-party
  // model may throw here — and with the assignment first, the shells' `catch`
  // would forget a live, open model with nobody left to close it. The closure
  // reads `_cached` when it fires, not now, so this order is safe.
  model.addCloseListener(() {
    // Identity-guarded, as the inference singleton and the session layer
    // already are. Without it a late close of a SUPERSEDED model clears
    // whatever is registered now — including a newer, live model, whose next
    // caller then reloads weights that are already in memory while the live
    // one leaks with nobody left to close it.
    if (!identical(_cached?.model, model)) return;
    _cached = null;
  });
  _cached = _CachedEmbedder(model, params);
}