/** * Deterministic, battery-owned pooling + L2-normalization for the transformers.js embeddings battery. * * @module @nhtio/adk/batteries/embeddings/transformers_js/pooling * * @remarks * Used when `poolingOwner: 'battery'`. The pipeline is asked for raw `pooling:'none'` token states — * a `[batch, seq, hidden]` tensor — and this module pools them into one vector per input in pure JS, * identically across Node and the browser. That removes the per-runtime post-processing variance that * widens the node↔browser cosine gap; only the irreducible ONNX-Runtime kernel floor remains. * * Pooling strategies mirror the transformers.js feature-extraction options: * - `mean` — attention-unaware mean over the sequence axis (matches the pipeline's `'mean'`, which * also means over all positions for a single ungrouped sequence). * - `cls` / `first_token` — the first token's hidden state. * - `eos` / `last_token` — the last token's hidden state. * - `none` — no pooling (caller already has the vector); returned unchanged per row. */ /** A 3-D `[batch, seq, hidden]` nested array (raw token states from `pooling:'none'`). */ export type TokenStates3D = number[][][]; /** A 2-D `[batch, hidden]` nested array (already-pooled vectors). */ export type Pooled2D = number[][]; /** * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned * unchanged (no divide-by-zero). * * @param vec - The vector to normalize. */ export declare const l2Normalize: (vec: number[]) => number[]; /** * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`). * * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`. * @param pooling - The pooling strategy (`'mean'` default). * @param normalize - Whether to L2-normalize each pooled vector (default `true`). * @returns One pooled (and optionally normalized) vector per batch row. */ export declare const poolAndNormalize: (tokenStates: TokenStates3D, pooling: string, normalize: boolean) => Pooled2D; /** Default {@link poolAndNormalize}. */ export declare const defaultPoolAndNormalize: (tokenStates: TokenStates3D, pooling: string, normalize: boolean) => Pooled2D;