/** * Query wrapper around trained embeddings: nearest-neighbour lookup and a * getRelated() adapter shaped exactly like the existing CoOccurrenceModel so it * can drop into expandQuery()/semanticSimilarity() in place of the PMI model. * * With subwords, a word's vector is the average of its own row (if in vocab) and * its subword rows — so even a rare or unseen word (the Korean long tail) gets a * composed vector and can find neighbours. Candidate neighbours are always the * in-vocab words; similarity uses L2-normalized rows (cosine == dot). An optional * precomputed top-K cache keeps in-vocab getRelated() O(1) on the hot path. */ import type { EmbeddingArtifact, ModelManifest, TrainedEmbeddings } from "./types.js"; export type Neighbour = { word: string; score: number; }; export declare class EmbeddingModel { readonly vocab: string[]; readonly dim: number; private readonly wordVectors; private readonly index; private readonly sub?; private _search; private readonly neighbors?; private readonly neighborScores?; constructor(vocab: string[], dim: number, wordVectors: Float32Array, opts?: { subwordVocab?: string[]; subwordVectors?: Float32Array; subwordCounts?: number[]; minN?: number; maxN?: number; cache?: { neighbors: number[][]; neighborScores: number[][]; }; }); static fromTrained(t: TrainedEmbeddings, cache?: { neighbors: number[][]; neighborScores: number[][]; }): EmbeddingModel; /** Strict word-vocabulary membership (defines the candidate-neighbour set). */ has(word: string): boolean; /** * Compose a vector for any word. In-vocab words return their PURE trained * vector (the semantic signal — subwords would only dilute it). Out-of-vocab * words — the rare Korean tail — return the average of their subword * centroids. null when the word has no representable constituents. */ private compose; /** Composed, L2-normalized in-vocab matrix used as the neighbour candidate set. */ private searchMatrix; /** Top-N most similar in-vocab tokens to `word` (works for OOV via subwords). */ mostSimilar(word: string, topN?: number): Neighbour[]; /** Adapter matching CoOccurrenceModel.getRelated — `pmi` carries the cosine score. */ getRelated(word: string, topN?: number): { word: string; pmi: number; }[]; /** Precompute the top-K in-vocab neighbour cache for every token (one-time). */ buildNeighborCache(topK: number): { neighbors: number[][]; neighborScores: number[][]; }; toArtifact(manifest: ModelManifest, cache: { neighbors: number[][]; neighborScores: number[][]; }): EmbeddingArtifact; static fromArtifact(a: EmbeddingArtifact): EmbeddingModel; }