/** * Semantic search with cosine similarity and keyword fallback. * Uses embedder for vector search, falls back to term-frequency * keyword search when ONNX is unavailable. */ import type { Embedder } from "./embedder.js"; import type { IIndexManager } from "../storage/interfaces.js"; import type { BlackboardEntry, Decision } from "../utils/types.js"; export interface BlackboardSearchResult { entry: BlackboardEntry; relevance: number; } export interface DecisionSearchResult { decision: Decision; relevance: number; } export interface SearchResults { results: T[]; /** * Pre-slice match count — never capped by limit (field D9). Membership is * tested on RAW scores, before any status de-boost: semantic mode counts * raw cosine >= SEARCH_NOISE_FLOOR (every embedded item gets a score, so * an unfloored count would equal the corpus size; noise sits ~0.26-0.28); * keyword mode counts every literal term hit (score > 0 — TF scores are a * different scale and a literal hit is never noise). The results page * itself is NOT floored — it stays a ranked page. */ total_matched: number; fallback_mode: boolean; } /** * Relevance below this is indistinguishable from noise (measured ~0.26-0.28 * cosine for nonsense queries on MiniLM). Used for total_matched counting * here and for assemble's semantic-admission floor. */ export declare const SEARCH_NOISE_FLOOR = 0.3; /** * Version stamp for count fields on search responses (2026-08-15 field * audit, ask 2): total_matched's meaning has changed across builds * (post-slice page length before 2.9.0; floored pre-page count since) and * field docs pinned to different generations coexist. Responses carry this * literal so a caller can tell which semantics it is reading. Bump ONLY * when count semantics actually change. */ export declare const COUNT_SEMANTICS = "pre_page_floored_v2"; export declare class SearchEngine { private readonly embedder; private readonly indexManager; constructor(embedder: Embedder, indexManager: IIndexManager); /** Search blackboard entries by semantic similarity or keyword fallback. */ searchBlackboard(query: string, entries: BlackboardEntry[], options?: { entry_types?: string[]; limit?: number; }): Promise>; /** Search decisions by semantic similarity or keyword fallback. */ searchDecisions(query: string, decisions: Decision[], options?: { limit?: number; }): Promise>; } /** * Cosine similarity for pre-normalized vectors (dot product). * Since all-MiniLM-L6-v2 outputs normalized vectors, cosine similarity * simplifies to the dot product. */ export declare function cosineSimilarity(a: number[], b: number[]): number; /** * Term-frequency based keyword search for fallback mode. * Scores each item by how many query terms appear and how often. */ export declare function keywordSearch(query: string, items: { id: string; text: string; }[], limit: number): { id: string; score: number; }[]; //# sourceMappingURL=search.d.ts.map