/** * Query Router + RRF fusion — Phase 4 of the cognee port plan. * * routeQuery: cognee's rule-based (non-LLM) recall router scaled to our four * retrieval surfaces — document chunks, knowledge-graph triplets, distilled * rules, and org/pattern memories. Weighted regex rules with a negation * window, a confidence gate (winner must be ≥2× runner-up), and an in-memory * misroute counter for debuggability. * * rrfFuse: Reciprocal Rank Fusion across result lists whose raw scores are * not comparable (cosine vs blended vs keyword) — `Σ 1/(rrf_k + rank + 1)` * with cognee's adaptive rrf_k = max(30, min(60, 20 + 2·top_k)). * * @module v1/cli/memory/query-router */ export type RetrievalSurface = 'chunks' | 'kg' | 'rules' | 'memory'; /** A retrieval surface by its real identity, not by the tool that fronts it. * `code_graph` is Monograph (parsed code) and is never served by knowledge * search — it appears in a report precisely so its absence is stated. */ export type KnowledgeSurface = 'documents' | 'memory_graph' | 'rules' | 'memory' | 'code_graph'; /** Router surface names → contract names. The router's vocabulary predates the * contract and is still what `--surfaces` / `surfaces:[]` accept. */ export declare const SURFACE_IDS: Record; export type SurfaceStatus = /** Ran and returned something. */ 'executed' /** Ran and legitimately had nothing — distinct from unavailable. */ | 'empty' /** Attempted and errored; absence here is not evidence of absence. */ | 'failed' /** This implementation cannot search it at all. */ | 'unsupported' /** Not part of this query's route. */ | 'not_requested'; export interface SurfaceOutcome { surface: KnowledgeSurface; status: SurfaceStatus; /** Which store/graph was actually read. */ scope?: { store?: 'project' | 'global' | 'all'; org?: string; }; /** What retrieval actually ran — never what was requested. Propagated from * the memory bridge (`semantic` / `keyword` / `keyword-fallback`) so a * keyword fallback can never be presented as vector-seeded search. */ method?: string; /** Why the vector path did not serve these results, when it did not. */ fallbackReason?: string; results?: number; /** The surface did not cover its whole namespace; results are incomplete. */ truncated?: boolean; detail?: string; } export interface RetrievalReport { requested: KnowledgeSurface[]; executed: KnowledgeSurface[]; failed: KnowledgeSurface[]; unsupported: KnowledgeSurface[]; surfaces: SurfaceOutcome[]; } /** Roll per-surface outcomes into the four lists callers actually branch on. * `executed` covers 'empty' too: the surface answered, the answer was none. */ export declare function buildRetrievalReport(outcomes: SurfaceOutcome[]): RetrievalReport; export interface RouteDecision { /** Surfaces to hit, best first. Always non-empty ('chunks' is the fallback). */ surfaces: RetrievalSurface[]; /** Winner's score ≥ 2× runner-up (cognee's confidence gate). Low-confidence * routes should hit ALL surfaces and fuse. */ confident: boolean; scores: Record; /** The query asks about code structure (callers/imports/references). No * knowledge-search surface can answer it — Monograph can. Callers must * either route to Monograph or report `code_graph` as not searched. */ codeQuery: boolean; } export declare function routeQuery(query: string): RouteDecision; /** Call when a route proved wrong (caller retried another surface) — counts * feed debugging, mirroring cognee's record_override telemetry. */ export declare function recordRouteOverride(from: RetrievalSurface, to: RetrievalSurface): void; /** In-memory counts from this process only; pass merged=true to include the * persisted cross-process counts from .monomind/metrics/route-overrides.json. */ export declare function getRouteOverrides(merged?: boolean): Record; export interface FusableResult { /** Stable identity across lists (id or key). */ id: string; /** Importance factor input in [0,1]; defaults 0.5. */ importance?: number; [extra: string]: unknown; } /** Fuse ranked lists via RRF × importance factor (cognee hybrid/ranking.py). * Input lists must each be ranked best-first; raw scores are ignored. */ export declare function rrfFuse(lists: T[][], topK: number): (T & { rrf: number; })[]; //# sourceMappingURL=query-router.d.ts.map