/** * ADR-005 retrieval eval harness. * * Seeds the shared eval corpus (contracts/fixtures/eval/corpus.json) into a * live database, runs the shared query set through the local search engine, * and scores recall@k / NDCG@k against the graded relevance judgments. * * Known v1 engine gaps, handled explicitly rather than silently: * - per-query `mode` (keyword|semantic|hybrid) is advisory only; the local * engine always runs its hybrid FTS+vector path. The mode is echoed in * the per-query report so a future mode-routing engine can be compared. * * FEAT-401: `as_of` (bitemporal time-travel) is now supported end-to-end — * seedEvalCorpus backfills each atom's declared valid_from (in addition to * valid_to) so corpus atoms carry their fixture-declared validity windows * rather than the insert-time "now", and runRetrievalEval forwards * `filters.as_of` straight into search() instead of skipping the query. * * FEAT-402 slice 2 (AC-8): each corpus atom may declare an `entities: string[]` * array (already present on every fixture atom since slice 1). seedEvalCorpus * links them via EntityRepo the same way distill-time extraction does, and a * query may declare `filters.entity` to exercise the AC-4 pre-fusion * intersection end-to-end. Fixture entities have no `kind` — seeded with the * generic 'concept' kind, which is irrelevant to filtering (name-only lookup). */ import type { DB } from '../storage/db.js'; import type { EmbedProvider } from '../contracts/index.js'; import type { RerankOpts } from '../search/rerank.js'; import { type GradedRelevance } from './metrics.js'; export interface EvalAtom { id: string; type: string; text: string; evidence: string | string[] | null; confidence: number; importance: number; provenance: { session_id: string; repo: string; project: string; }; /** Bitemporal valid-time start (ADR-001). Optional for pre-FEAT-401 fixtures. */ valid_from?: string; valid_to: string | null; scope: string; content_hash: string; /** FEAT-402 slice 2 AC-8: entity names linked to this atom (kind-less — seeded as 'concept'). */ entities?: string[]; } export interface EvalQuery { id: string; text: string; mode: string; filters: { type?: string[]; as_of?: string; entity?: string; }; graded_relevant: GradedRelevance[]; } export interface EvalCorpus { atoms: EvalAtom[]; } export interface EvalQuerySet { queries: EvalQuery[]; } export interface QueryResult { id: string; mode: string; skipped: string | null; recall: number | null; ndcg: number | null; rankedAtomIds: string[]; } export interface EvalReport { k: number; perQuery: QueryResult[]; evaluated: number; skipped: number; meanRecall: number; meanNdcg: number; } /** * Insert every corpus atom into the DB (memories + FTS via trigger + vector * index). Returns memory-id → atom-id so engine hits can be scored against * the corpus judgments. Atoms with a non-null valid_to are marked * invalidated after insert, matching their bitemporal state. */ export declare function seedEvalCorpus(db: DB, embed: EmbedProvider, corpus: EvalCorpus): Promise>; export declare function runRetrievalEval(db: DB, embed: EmbedProvider, weights: { alpha: number; beta: number; gamma: number; delta: number; epsilon: number; zeta?: number; }, corpus: EvalCorpus, querySet: EvalQuerySet, k?: number, rerank?: RerankOpts): Promise;