export declare function initEmbedder(): Promise; export declare function embed(texts: string[]): Promise; export declare function cosineSimilarity(a: Float32Array, b: Float32Array): number; /** * Per-token embedding for late-interaction reranking (#29). * * Returns one TokenEmbedding per input text, where each TokenEmbedding holds * the L2-normalized per-token hidden states in a flat Float32Array of length * `len * dim`. The flat layout (vs `Float32Array[]`) is intentional: the * MaxSim hot path benchmarks 3-5x faster on a contiguous buffer because V8 * inlines the tight `q ยท d` loop aggressively. * * Padding (attention_mask = 0) and special tokens (CLS at position 0, SEP at * position word-count + 1) are stripped โ€” only "real content" tokens come * back. This matches what ColBERT-style scoring expects: the scoring runs * over genuinely meaningful positions, not padding. * * Returns null when the ONNX runtime is unavailable. Callers (rerank.ts) use * that to silently fall through to pass-through behavior โ€” never throw, the * production retrieval path must not break behind a model load failure. * * Shape contract: * embedTokens(["hello world"]) โ†’ [{ tokens: Float32Array([...]), dim: 384, len: 2 }] * tokens[t * dim + d] is the d-th component of the t-th token's vector. */ export interface TokenEmbedding { /** Flat per-token hidden states of length len * dim. L2-normalized per token. */ tokens: Float32Array; /** Embedding dimensionality (384 for all-MiniLM-L6-v2). */ dim: number; /** Number of real tokens kept (CLS/SEP/padding stripped). */ len: number; } export declare function embedTokens(texts: string[]): Promise<(TokenEmbedding | null)[]>; export declare const EMBEDDING_DIM = 384;