/** * Optional semantic re-ranking for The Brain. * * TheBrainV2 retrieves lexically: BM25 over an inverted index, Jaccard re-rank, plus a * hand-written table of bilingual synonym clusters. That table is the tell — it exists * because a memory stored as "race condition al flushear el índice invertido" is invisible * to a search for "why do memories disappear", and every new vocabulary gap needs another * hand-written cluster. Embeddings close that class of gap without a maintained word list. * * What it deliberately does NOT do: * - become a dependency. Off unless LEMMA_BRAIN_EMBEDDINGS is set, and every failure path * (no Ollama, no model, timeout, malformed response) silently degrades to pure BM25. * The module's zero-dependency, sub-10ms-per-query design stays the default. * - replace retrieval. BM25 still selects the candidate set; embeddings only reorder it. * A memory the inverted index never surfaces can't be rescued here — which is the * conservative direction, since a wrong reordering costs a place in a list while a wrong * retrieval costs a wrong answer. * - block. One probe decides availability for the whole session, each request has a hard * timeout, and the number of vectors computed per call is capped. * * Vectors live in their own sidecar file, never in entries.ndjson: 768 floats per entry * would multiply the corpus every session re-reads at startup by an order of magnitude, for * data only this optional path ever reads. */ /** Enabled only on an explicit opt-in — see the module comment. */ export declare function embeddingsEnabled(): boolean; export interface EmbeddedCandidate { id: string; /** Lexical similarity from TheBrainV2.search(), already normalized 0-1. */ similarity: number; /** Text to embed when this candidate has no vector yet. */ text: string; } export declare function resetEmbeddingAvailability(): void; export declare function cosine(a: number[], b: number[]): number; /** Sidecar vector store, keyed by entry id and tagged with the model that produced it. */ export declare class EmbeddingSidecar { private file; private vectors; private model; private loaded; constructor(file: string); private load; get(id: string): number[] | undefined; set(id: string, vec: number[]): void; /** Drops vectors for ids no longer in the corpus, then rewrites the sidecar atomically. */ flush(liveIds: Set): void; } /** * Blend semantic similarity into an already-ranked candidate list. * * Returns the ids in their new order along with the blended scores, or null when embeddings * are unavailable — the caller then keeps the lexical ordering untouched. Candidates with no * vector (budget exhausted this call) keep their lexical score rather than being scored * against a zero vector, which would drop them below every scored candidate for no reason * other than arriving late in the queue. */ export declare function semanticRerank(query: string, candidates: EmbeddedCandidate[], sidecar: EmbeddingSidecar): Promise | null>; //# sourceMappingURL=BrainEmbeddings.d.ts.map