import type { FtsIndex } from "./fts5.js"; import type { Vault } from "./vault.js"; /** A single evaluation query — relevant doc paths are the ground truth. */ export interface EvalQuery { /** Query text fed to obsidian_search. */ query: string; /** * Vault-relative paths considered relevant. Order doesn't matter — we * only need the set membership. Paths are matched against * `SearchHybridHit.path` exactly. */ relevant: string[]; /** Optional human-readable id for logging / reports. */ id?: string; /** * v3.11.6-rc.5 — optional grouping key (e.g. `keyword` / `conceptual` / * `temporal-reasoning` / `knowledge-update`). When present, `runEval` reports * the same metrics per category in `EvalResult.by_category`, so a maintainer * can see WHICH class of query is weak (the highest-value diagnostic slice). */ category?: string; } /** Per-query scores. */ export interface EvalQueryScore { id: string; query: string; /** Normalized Discounted Cumulative Gain @ K. */ ndcg_at_k: number; /** Recall @ K — fraction of relevant docs in top-K. */ recall_at_k: number; /** Mean Reciprocal Rank — 1/rank of first relevant; 0 if none in top-K. */ mrr: number; /** Number of relevant docs found anywhere in the top-K. */ hits_relevant: number; /** Total relevant docs in the ground truth. */ hits_total_relevant: number; /** Latency for this query in milliseconds. */ latency_ms: number; /** * v3.11.6-rc.5 (eval overhaul) — additive diagnostics (all optional so * hand-built `EvalQueryScore`s stay valid; `runEval` always populates them). */ /** Grouping key echoed from the query (for `by_category`). */ category?: string; /** A relevant doc is at rank 1. */ hit_at_1?: boolean; /** At least one relevant doc is in the top-K (binary). */ hit_at_k?: boolean; /** EVERY relevant doc is in the top-K — the stricter multi-evidence signal (AllRel). */ all_relevant_at_k?: boolean; /** Relevant paths NOT retrieved in top-K — the first files to inspect on a low recall. */ missed_paths?: string[]; /** The top-K retrieved paths in rank order — what outranked the missed docs. */ top_paths?: string[]; /** * v3.9.0-rc.16 — true if `searchHybrid` threw for this query (transient * infra failure, embedder OOM, etc.). The query's scores are all 0 and it * still counts toward the means — an errored query is NOT silently dropped, * but it IS distinguishable from a genuine zero-relevance retrieval. Absent * (undefined) on successful queries. */ error?: boolean; /** * v3.10.0-rc.31 — retrieval-failure classification for this query (see * {@link classifyFailureBucket}). Lets a maintainer see *why* a query scored * low (ranked-but-not-rank-1 vs missed entirely) without reading every hit. */ failure_bucket: FailureBucket; } /** Aggregate evaluation result. */ export interface EvalResult { /** Configuration label — useful for the matrix mode. */ label: string; k: number; query_count: number; /** * v3.9.0-rc.16 — number of queries that threw during retrieval (counted in * `query_count` and in the means as zeros). > 0 means the means are deflated * by infra failures, not retrieval quality — re-run before publishing. */ query_errors: number; /** Per-query scores. */ per_query: EvalQueryScore[]; /** Mean NDCG@K across all queries. */ mean_ndcg: number; /** Mean Recall@K across all queries. */ mean_recall: number; /** Mean Reciprocal Rank across all queries. */ mean_mrr: number; /** Mean latency in milliseconds. */ mean_latency_ms: number; /** Total run wall time. */ total_wall_ms: number; /** * v3.11.6-rc.5 (eval overhaul) — additive aggregate diagnostics (optional so * hand-built results stay valid; `runEval` always populates them). */ /** Fraction of queries with a relevant doc at rank 1 (Hit@1). */ mean_hit_at_1?: number; /** Fraction of queries with any relevant doc in top-K (Hit@K). */ mean_hit_at_k?: number; /** Fraction of queries where EVERY relevant doc is in top-K (AllRel@K). */ all_rel_at_k?: number; /** Same metrics grouped by `EvalQuery.category` — the weak-slice diagnostic. */ by_category?: Record; /** * v3.10.0-rc.31 — aggregate retrieval-failure-bucket counts across all * queries (see {@link classifyFailureBucket}). Optional so externally * hand-built `EvalResult`s (e.g. `scripts/run-benchmarks.mjs`) stay valid; * `runEval` always populates it. */ diagnostics?: { failure_buckets: Record; }; } /** * NDCG@K with binary relevance. * * DCG@K = sum_{i=1..K} rel_i / log2(i + 1) * IdealDCG@K = sum_{i=1..min(K, |relevant|)} 1 / log2(i + 1) * NDCG@K = DCG@K / IdealDCG@K * * Returns 0 when `relevant` is empty (no ground truth → undefined ratio). */ export declare function ndcgAtK(retrievedPaths: string[], relevant: ReadonlySet, k: number): number; /** Recall @ K = |retrieved ∩ relevant| / |relevant|. */ export declare function recallAtK(retrievedPaths: string[], relevant: ReadonlySet, k: number): number; /** Mean Reciprocal Rank — 1/rank of first relevant; 0 if none in top-K. */ export declare function reciprocalRank(retrievedPaths: string[], relevant: ReadonlySet, k: number): number; /** * Hit@K — is ANY relevant doc in the top-K? Binary. `atRank` (default 1) lets * you ask Hit@1 vs Hit@3 vs Hit@5 by capping the window. `false` when there is * no ground truth (empty `relevant`). Pure. (v3.11.6-rc.5 eval overhaul.) */ export declare function hitAtK(retrievedPaths: string[], relevant: ReadonlySet, k: number): boolean; /** * AllRel@K — is EVERY relevant doc present in the top-K? The stricter * multi-evidence signal (a query needing 3 evidence notes only counts if all 3 * are retrieved). `false` when there is no ground truth. Pure. (rc.5.) */ export declare function allRelevantAtK(retrievedPaths: string[], relevant: ReadonlySet, k: number): boolean; /** The relevant paths NOT found in top-K — the first files to inspect on a low recall. Pure. (rc.5.) */ export declare function missedPaths(retrievedPaths: string[], relevant: ReadonlySet, k: number): string[]; /** Per-category aggregate metrics (a slice of the whole-run aggregate). */ export interface CategoryScore { query_count: number; mean_ndcg: number; mean_recall: number; mean_mrr: number; mean_hit_at_1: number; mean_hit_at_k: number; all_rel_at_k: number; } /** * Group scored per-query rows by their `category` and compute the same means * per group. Rows with no category are grouped under `uncategorized`. Pure — * derived entirely from the already-scored `per_query`, so it never re-runs a * search. (v3.11.6-rc.5 — the highest-value OHS-inspired diagnostic.) */ export declare function groupByCategory(perQuery: readonly EvalQueryScore[]): Record; /** One metric's before/after delta in an A/B comparison. */ export interface MetricDelta { metric: string; baseline: number; after: number; delta: number; /** true iff `|delta| >= MEANINGFUL_DELTA` (statistically meaningful at ~50+ queries). */ meaningful: boolean; } /** Delta threshold below which a change is noise at ~50+ queries (OHS convention). */ export declare const MEANINGFUL_DELTA = 0.01; export interface EvalComparison { baseline_label: string; after_label: string; deltas: MetricDelta[]; } /** * Compare two EvalResults (baseline vs after) into a delta table. Compares the * whole-run aggregate metrics; a `|delta| >= MEANINGFUL_DELTA` is flagged * meaningful. Pure — the A/B tool that makes a retrieval change PROVABLE rather * than asserted. (v3.11.6-rc.5.) */ export declare function compareEvalResults(baseline: EvalResult, after: EvalResult): EvalComparison; /** Render an EvalComparison as a delta table (used by `scripts/eval-compare.mjs`). */ export declare function formatEvalComparison(cmp: EvalComparison): string; /** * Per-query retrieval-failure classification — a seeklink-inspired diagnostic * that turns a bare "the score is low" into "*why* it's low", so a maintainer * tuning retrieval knows where to look. * * The buckets are derived ONLY from the scored top-K result set (the data the * eval already has), so adding them is a zero-behavior-change, zero-extra-cost * diagnostic — the metric numbers are untouched. * * - `error` — `searchHybrid` threw for this query (infra, not relevance). * - `no_labels` — the query has no ground-truth `relevant` paths to score. * - `hit_rank_1` — a relevant doc is at rank 1 (ideal). * - `hit_top_k` — a relevant doc is in the top-K but not at rank 1 (ranking * could be tighter — a reranker-ordering signal). * - `miss` — no relevant doc in the top-K. * * NOTE (deferred): seeklink further splits `miss` into "candidate-generation * miss" (never retrieved) vs "ranking-budget / reranker-ordering miss" * (retrieved but ranked below K). That split needs a retrieval WIDER than K to * see where the expected doc landed — and widening the eval search would change * the reranker's candidate budget and thus the scored numbers, breaking * historical comparability. It is therefore deliberately NOT done here; a * future first-stage-diagnostics plumbing change (returning pre-rerank * candidates from `searchHybrid`) would enable it without that side effect. */ export type FailureBucket = "error" | "no_labels" | "hit_rank_1" | "hit_top_k" | "miss"; /** The five buckets, in display order — also the keys of the aggregate counter. */ export declare const FAILURE_BUCKETS: readonly FailureBucket[]; /** Classify a single query's outcome from its scored top-K paths. Pure. */ export declare function classifyFailureBucket(retrievedPaths: readonly string[], relevant: ReadonlySet, k: number, errored?: boolean): FailureBucket; /** Tally a list of per-query buckets into a complete counter (all keys present). */ export declare function tallyFailureBuckets(buckets: readonly FailureBucket[]): Record; /** * Read a JSONL file of EvalQuery objects. Tolerates blank lines and * comments (lines starting with `//`). Throws on invalid JSON or * missing required fields. */ export declare function readQueriesJsonl(file: string): Promise; export interface RunEvalOptions { vault: Vault; queries: readonly EvalQuery[]; ftsIndex: FtsIndex | null; embedFile: string; k?: number; /** Label for the result — useful when running multiple configurations. */ label?: string; /** Pass-through to searchHybrid (e.g. graph_boost, min_signals). */ searchOpts?: { graph_boost?: boolean; min_signals?: number; embedding_model?: string; }; /** Optional reranker config — pass-through to searchHybrid. */ reranker?: { alias?: string; topN?: number; }; /** Test-only DI for mocking the reranker. */ rerankerOverride?: { score(query: string, passages: readonly string[]): Promise; }; } /** * Run obsidian_search across a set of evaluation queries and compute * NDCG@K, Recall@K, MRR. Returns a fully-populated EvalResult. * * `embedFile` may be a non-existent path — embeddings simply won't * contribute (graceful degradation matches `searchHybrid` behavior). */ export declare function runEval(opts: RunEvalOptions): Promise; /** * Render an EvalResult as a pretty CLI table. ANSI-colored when stdout * is a TTY, plain text otherwise (so `enquire eval | tee report.txt` * stays readable). */ export declare function formatEvalResult(result: EvalResult, opts?: { perQuery?: boolean; }): string; /** * Render multiple EvalResults side-by-side as a comparison matrix. Used * by `enquire eval --matrix` to A/B several configurations in one run. */ export declare function formatEvalMatrix(results: readonly EvalResult[]): string; //# sourceMappingURL=eval.d.ts.map