/** * Zero-Dependency Semantic Similarity Engine * * Captures meaning without embeddings or external APIs. * * Three mechanisms: * * 1. SYNONYM GRAPH * Hard-coded domain knowledge mapping related concepts. * "deploy" ↔ "release" ↔ "publish" ↔ "배포" ↔ "ship" * Bilingual: English ↔ Korean for dev terminology. * * 2. CO-OCCURRENCE PMI (Pointwise Mutual Information) * Learns from the corpus itself: words that appear together * more than expected by chance are semantically related. * "authentication" frequently near "password" → related. * No training, no model — pure statistics. * * 3. QUERY EXPANSION * Expands search query with synonyms + co-occurrence neighbors. * "deploy" → ["deploy", "release", "publish", "배포", "ship"] * Then runs BM25 on expanded query → semantic matches found. */ /** Each group = mutually synonymous concepts. */ export declare const SYNONYM_GROUPS: string[][]; /** Get synonyms for a word. */ export declare function getSynonyms(word: string): string[]; export type CoOccurrenceModel = { /** Get top-N semantically related words for a given word. */ getRelated: (word: string, topN?: number) => { word: string; pmi: number; }[]; /** Rebuild from a new corpus. */ rebuild: (documents: string[]) => void; /** Number of unique terms. */ vocabSize: () => number; }; export declare function stem(word: string): string; /** Transliterate Korean loanword to English equivalent. */ export declare function transliterate(word: string): string | undefined; /** Trigram Jaccard similarity between two words. Returns 0-1. */ export declare function trigramSimilarity(a: string, b: string): number; export declare function tokenize(text: string): string[]; export declare function createCoOccurrenceModel(): CoOccurrenceModel; export type ExpandedQuery = { /** Original query tokens. */ original: string[]; /** Expanded tokens (includes original + synonyms + co-occurrence). */ expanded: string[]; /** Which tokens were added and why. */ expansions: { token: string; source: "synonym" | "cooccurrence" | "stem" | "transliteration" | "embedding"; relatedTo: string; }[]; }; /** Anything that can return related words — both CoOccurrenceModel and the * learned EmbeddingModel satisfy this, so either can feed query expansion. */ export type RelatedSource = { getRelated: (word: string, topN?: number) => { word: string; pmi: number; }[]; }; /** * Expand a query with semantic neighbors. * * "deploy error" → ["deploy", "release", "publish", "배포", * "error", "bug", "issue", "에러", * + co-occurrence neighbors] */ export declare function expandQuery(query: string, coModel?: CoOccurrenceModel, maxCoOccurrencePerToken?: number, embModel?: RelatedSource, maxEmbeddingPerToken?: number, minEmbeddingScore?: number): ExpandedQuery; /** * Compute semantic similarity between two texts. * * Five signals combined: * 1. Direct token overlap (Jaccard) * 2. Synonym + transliteration expanded overlap * 3. Stemmed overlap * 4. Trigram fuzzy match (catches morphological variants) * 5. Co-occurrence similarity * * Returns 0-1. */ export declare function semanticSimilarity(textA: string, textB: string, coModel?: CoOccurrenceModel): number;