Documentation
¶
Overview ¶
Package askeval implements issue #266's offline end-to-end evaluation runner for POST /api/v1/ask: it drives the REAL handler (internal/api, via httptest — see runner.go) against a synthetic, isolated corpus (see corpus.go) and a scripted LLM (see llm.go), so retrieval, query rewriting, the query planner, excerpt budgeting, synthesis, and the deterministic citation validator (issue #268) all run exactly as they do in production — never a mock of /ask's own logic.
This package intentionally contains NO real personal data: every fixture in eval/ask/fixtures/ is synthetic, and the corpus it builds exists only for the duration of one Run call (see runner.go's per-fixture *corpus).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixtureSetHash ¶
FixtureSetHash is a short, deterministic digest of the exact fixture content Load returned — report.go's Provenance.FixtureSetHash. Two Runs with different hashes are NOT diffable (DiffReports refuses): the fixture set itself changed, so a pass/fail delta would not mean "the code changed", it would mean "the test changed".
Types ¶
type CaseMetrics ¶
type CaseMetrics struct {
// RetrievalHit: every Gold.SupportDocs document ID appears in the
// "sources" SSE event — retrieval FOUND the evidence, independent of
// whether the excerpt budget kept it in the prompt. Only meaningful
// for an answerable, non-adversarial fixture, or an adversarial-citation
// fixture whose Gold declares SupportDocs. nil (omitted from JSON) for
// every other fixture shape — deep-verify #266 LOW finding: a bare
// `false` here for a fixture where the field means nothing (e.g. every
// unanswerable fixture) read as a real negative result to a report
// consumer scanning JSON, when in fact retrieval was never even
// evaluated for this fixture.
RetrievalHit *bool `json:"retrieval_hit,omitempty"`
// ContextHit: every Gold.SupportSpans string is a substring of the
// EXACT text the real pipeline placed in the Stage 3 synthesis prompt
// (captured via scriptedCompleter.synthesisPrompt) — retrieval finding
// the document is not sufficient if buildBudgetedAskMessages' excerpt
// budget clipped the passage before the gold sentence (deep-plan #268
// finding F2). RetrievalHit==true && ContextHit==false is exactly the
// "retrieval succeeded, context assembly failed" case issue #266 asks
// to distinguish from a plain retrieval miss. nil (omitted from JSON)
// when not applicable — see RetrievalHit's doc comment.
ContextHit *bool `json:"context_hit,omitempty"`
// AnswerCorrect: every Gold.Claims substring appears in the answer
// text. Only meaningful for an answerable, non-adversarial fixture; nil
// (omitted from JSON) for every other fixture shape — see RetrievalHit's
// doc comment.
AnswerCorrect *bool `json:"answer_correct,omitempty"`
// CitationStatus mirrors the done event's verification.citation_status
// (issue #268's askCitationStatus values: valid/invalid/missing/
// abstained/unverified), or "no_evidence" when synthesis never ran at
// all (verification is absent on that finish_reason by design).
CitationStatus string `json:"citation_status,omitempty"`
// InferredCited is true when the done event's
// verification.inferred_cited_ids is non-empty — the "추론을 사실로
// 인용" regression signal (ask_evidence.go's askEvidenceLayer doc
// comment).
InferredCited bool `json:"inferred_cited,omitempty"`
// AbstainedCorrectly: an UNANSWERABLE fixture (Gold.Answerable==false)
// got finish_reason "no_evidence" or citation_status "abstained".
AbstainedCorrectly bool `json:"abstained_correctly,omitempty"`
// FabricatedAnswer: an UNANSWERABLE fixture (Gold.Answerable==false,
// Gold.ExpectedCitationStatus unset) produced a NON-abstaining answer
// that actually cited something (verification.cited_ids non-empty) —
// the model claimed a fact instead of declining. This is the detector
// deep-verify #266 HIGH finding asked for: before it existed, every
// no_evidence/irrelevant_evidence fixture relied entirely on
// scriptedCompleter's own oracle (llm.go's synthesize), which ALWAYS
// returns the fixed abstention phrase whenever Gold.SupportSpans is
// empty — true for every such fixture — so these categories could never
// fail no matter how badly a real regression broke abstention handling;
// nothing exercised the "the pipeline answered anyway" path at all. A
// fixture whose ScriptedAnswer bypasses the oracle to deliberately
// fabricate such an answer (see fixture.go's Fixture.ScriptedAnswer,
// ne-04/05 and ie-04/05 in eval/ask/fixtures/) makes this field the
// fixture's OWN pass signal (see computeMetrics' default case) instead
// of a byproduct of AbstainedCorrectly: an independent check computed
// from the citation report rather than merely the logical negation of
// AbstainedCorrectly, so a future change that loosens
// isAskAbstentionAnswer/AbstainedCorrectly's own definition cannot
// silently make this whole category pass again by definition. Always
// false (and always the logical negation of AbstainedCorrectly) outside
// the default/unanswerable branch — see computeMetrics.
FabricatedAnswer bool `json:"fabricated_answer,omitempty"`
// FalseAbstention: an ANSWERABLE fixture got no_evidence/abstained
// instead of a claim — "normal-answer loss" (issue #266 completion
// criteria: report loss on ordinary questions, not just gains on
// adversarial ones).
FalseAbstention bool `json:"false_abstention,omitempty"`
// Pass is this case's single pass/fail rollup — see computeMetrics for
// the exact rule per fixture shape (adversarial-citation vs answerable
// vs unanswerable). report.go's category/summary counts are built from
// this field alone.
Pass bool `json:"pass"`
// AnswerBytes/PromptBytes are byte-size cost PROXIES (issue #266
// completion criteria requires stating this explicitly): actual token
// cost depends on the configured model's tokenizer, which this offline
// scripted run never calls.
AnswerBytes int `json:"answer_bytes"`
PromptBytes int `json:"prompt_bytes"`
LatencyMS map[string]float64 `json:"latency_ms,omitempty"`
}
CaseMetrics is one fixture's scored outcome. Every field is a DETERMINISTIC detector result computed from what the real /ask pipeline actually produced for this fixture (runner.go's CaseResult) — never a semantic judge (issue #266 scope explicitly excludes a runtime LLM judge; see report.go's Provenance.JudgeMode for the shadow-only exception).
type CaseResult ¶
type CaseResult struct {
Fixture Fixture
Metrics CaseMetrics
RawAnswer string
Sources []sourceItem
Plan *planPayload
Verification *verificationPayload
FinishReason string
LatencyMS map[string]float64
// Err is set when the fixture itself could not be executed at all (a
// harness/fixture-authoring bug: bad as_of, unresolvable alias,
// scripted-LLM contract violation) — distinct from a normal metric
// failure, which always has Err==nil and a Metrics.Pass==false
// instead. report.go surfaces Err separately so a broken fixture is
// never silently counted as "the pipeline produced a wrong answer".
Err error
}
CaseResult is one fixture's raw run outcome plus its scored CaseMetrics.
func Run ¶
func Run(ctx context.Context, fixtures []Fixture, opts RunOptions) []CaseResult
Run executes every fixture against the REAL /ask handler (api.Server, via httptest) and returns one CaseResult per fixture, in input order.
Fixtures run strictly SEQUENTIALLY, one *api.Server per fixture: each fixture declares its own isolated corpus (Fixture.Corpus), and the scripted LLM (llm.go) is stateful — forFixture rebinds its currently- scripted fixture and resets its call log — so two fixtures in flight at once would race on which one is being scripted at any given moment. This keeps the runner simple and fully deterministic at the cost of wall-clock time; parallelizing across fixtures (each with its own scriptedCompleter instance) is possible future work, not required by issue #266's completion criteria.
type CaseSummary ¶
type CaseSummary struct {
ID string `json:"id"`
Category string `json:"category"`
Pass bool `json:"pass"`
Metrics CaseMetrics `json:"metrics"`
// Error is non-empty exactly when the source CaseResult.Err was set —
// a harness/fixture bug, not a pipeline-quality finding. Pass is
// forced false whenever Error is set, but a report reader must not
// conflate the two: a non-empty Error means this fixture measured
// NOTHING, not that it measured a failure.
Error string `json:"error,omitempty"`
}
CaseSummary is one fixture's report row.
type CategorySummary ¶
type CategorySummary struct {
Category string `json:"category"`
Total int `json:"total"`
Passed int `json:"passed"`
}
CategorySummary aggregates CaseMetrics.Pass for one fixture category.
type CorpusDoc ¶
type CorpusDoc struct {
// Alias is this fixture's own stable name for the document — NEVER a
// UUID. aliasID (corpus.go) derives a deterministic uuid.UUID from it,
// so the same alias always maps to the same document ID on every run
// (required for Gold.SupportDocs references and report.go's baseline
// diff to stay meaningful across runs).
Alias string `json:"alias"`
// SourceType is a model.SourceType string value (e.g. "gmail",
// "call", "calendar"). Kept as a plain string here — this file does
// not import internal/model — and converted in corpus.go.
SourceType string `json:"source_type"`
Title string `json:"title"`
Content string `json:"content"`
// OccurredAt is RFC3339 ("2026-06-10T09:00:00+09:00"); empty means nil
// — the "unknown event time", not "same day as now", distinction
// ask.go's formatOccurredAt exists to preserve. A fixture that needs a
// window/source-filter test to actually exclude this document MUST set
// this field: assembleRetrieval's plan.OccurredFrom/To predicate drops
// every row with a nil OccurredAt once either bound is set
// (model.SearchQuery.OccurredFrom's doc comment).
OccurredAt string `json:"occurred_at,omitempty"`
}
CorpusDoc is one document a fixture's isolated corpus contains.
type Diff ¶
type Diff struct {
FixtureSetHash string
Improved, Regressed []string
StillFailing, StillPassing []string
Summary string
}
Diff is a per-case pass/fail delta between two reports built from the SAME fixture set — never a bare aggregate-score difference, which can hide a fixture that flipped pass->fail while another flipped the other way (issue #266 completion criteria: report failing cases explicitly).
func DiffReports ¶
DiffReports compares baseline against candidate. Both MUST share the same Provenance.FixtureSetHash — a different hash means the fixture set itself changed between runs, so any pass/fail delta would describe a test change, not a code change, and DiffReports refuses to produce one.
type Fixture ¶
type Fixture struct {
ID string `json:"id"`
Category string `json:"category"`
// AsOf is this fixture's "now" (RFC3339), injected into the real
// pipeline via api.Server.WithClock (ask_eval_hooks.go) so "어제"/
// "지난주" resolve the same way regardless of when this fixture is
// actually executed.
AsOf string `json:"as_of"`
Corpus []CorpusDoc `json:"corpus"`
History []Turn `json:"history,omitempty"`
Question string `json:"question"`
// StandaloneQuestion is the scripted answer to the query-rewrite call
// (ask_rewrite.go) when History is non-empty — rewriteStandaloneQuestion
// never calls the LLM for a first turn, so this is ignored and may be
// left empty when History is empty.
StandaloneQuestion string `json:"standalone_question,omitempty"`
// ScriptedAnswer, when non-empty, is returned verbatim (after
// "{{doc:<alias>}}"/"{{fake}}" placeholder substitution — see llm.go)
// as the synthesis answer, overriding the default evidence-echo oracle.
// Required for every adversarial-citation fixture (Gold.
// ExpectedCitationStatus set); must be empty for every other category,
// so the default context-conditional oracle — and therefore the
// RetrievalHit/ContextHit detectors, which read the REAL prompt the
// oracle saw — actually runs.
ScriptedAnswer string `json:"scripted_answer,omitempty"`
// SemanticAliases declares synonym groups the FAKE VECTOR EMBEDDER
// (corpus.go's hashedEmbedder/hashEmbed, via semanticAliasFold) treats
// as interchangeable: every member of a group is folded to that group's
// first ("canonical") member before the bigram hash runs, for BOTH the
// query text and every chunk's text — so a question that paraphrases a
// chunk's actual wording (e.g. asks about "마감일" when the transcript
// says "완료 기준일") still hashes into overlapping features, the same
// way a real embedding model would place semantically-close paraphrases
// near each other in vector space.
//
// This package's fake embedder otherwise has NO notion of semantics at
// all (hashEmbed is a literal character-bigram hash — see its doc
// comment): SemanticAliases exists precisely to simulate a real vector
// model's paraphrase recall for fixtures that need to exercise the
// chunk-vector lane finding a passage the question's own words do not
// literally contain (deep-plan #267 finding: the chunk-vector lane is
// what actually recovers a paraphrased mid/late-transcript fact once
// its evidence is preserved through fusion).
//
// Deliberately scoped to hashedEmbedder ONLY — corpus.go's lexical
// lanes (Search's lexicalScore, chunkLexical) never see a folded text,
// so a synonym never leaks into the fake FTS/document lane. If it did,
// a fixture built to show "the vector lane recovers what the lexical
// lane misses" would recover on BOTH lanes and stop being a
// discriminating test — see docs/ask-evaluation-protocol.md's
// "semantic_aliases" section for the full rationale and the control
// check that verifies this scoping.
SemanticAliases [][]string `json:"semantic_aliases,omitempty"`
Gold Gold `json:"gold"`
}
Fixture is one askeval E2E test case.
type Gold ¶
type Gold struct {
// Answerable is false for the "no-evidence"/"unanswerable" category:
// the expected outcome is abstention (finish_reason "no_evidence" or a
// citation_status "abstained" answer), not any claim. Ignored when
// ExpectedCitationStatus is set (the adversarial-citation category has
// its own pass rule — see computeMetrics).
Answerable bool `json:"answerable"`
// Claims are short, literal Korean substrings the answer text must
// contain for an answerable fixture to pass (checked verbatim — issue
// #266 scope explicitly excludes a runtime LLM judge; see llm.go's
// scriptedCompleter for how the default oracle produces exactly these
// strings when the evidence was actually shown to it).
Claims []string `json:"claims,omitempty"`
// SupportDocs names Corpus[i].Alias values: the documents that back
// every Claims entry, used for the RetrievalHit detector (metrics.go).
SupportDocs []string `json:"support_doc_ids,omitempty"`
// SupportSpans are literal substrings of a SupportDocs entry's Content
// that must appear in the EXACT text the real pipeline placed in the
// Stage 3 synthesis prompt for the corresponding claim to be
// checkable at all — retrieval finding the document is necessary but
// not sufficient (deep-plan #268 finding F2; metrics.go's ContextHit).
SupportSpans []string `json:"support_spans,omitempty"`
// ExpectedCitationStatus, when set, switches computeMetrics into
// adversarial-detector mode: Pass becomes "did the real, unmodified
// askCitationStatus verdict (issue #268) equal this value", not
// "did the answer contain every Claims string". Used by the
// adversarial-citation fixtures (fake UUID, malformed link,
// prior-turn-only ID), whose ScriptedAnswer intentionally cites a bad
// ID — the CORRECT, passing outcome for those fixtures is that the
// real validator catches it, not that the answer "succeeds".
ExpectedCitationStatus string `json:"expected_citation_status,omitempty"`
// ExpectInferredCitation additionally requires the done event's
// verification.inferred_cited_ids to be non-empty — the
// "추론을 사실로 인용" regression signal (ask_evidence.go's
// askEvidenceLayer doc comment) the inferred-as-fact fixture exists to
// exercise. Only meaningful alongside ExpectedCitationStatus=="valid"
// (citing an inferred-layer document is ALLOWED, just flagged).
ExpectInferredCitation bool `json:"expect_inferred_citation,omitempty"`
}
Gold is a fixture's ground truth: what the real /ask pipeline SHOULD produce for Question, given History and the fixture's own Corpus.
type Provenance ¶
type Provenance struct {
GitRev string `json:"git_rev,omitempty"`
FixtureSetHash string `json:"fixture_set_hash"`
Cases int `json:"cases"`
// Mode is "scripted" (this runner's only implemented mode, issue #266
// scope) or "configured" (a real LLM backend — reserved for future
// work, never on by default).
Mode string `json:"mode"`
// JudgeMode is "off" (default; claim_support stays
// askClaimSupportNotEvaluated end to end) or "shadow" (a semantic judge
// runs but is NEVER a pass gate — issue #266 scope: "judge 실패/불일치를
// 정상 통과로 처리하지 않는다" means judge disagreement can only ever
// subtract from a result, never add).
JudgeMode string `json:"judge_mode"`
}
Provenance records what one Run measured — never a live claim about production quality (issue #266 completion criteria: "수치 근거 없이 개선을 단정하지 않는다"). Two reports with different FixtureSetHash values are not comparable; DiffReports refuses to diff them.
type Report ¶
type Report struct {
Provenance Provenance `json:"provenance"`
Cases []CaseSummary `json:"cases"`
Categories []CategorySummary `json:"categories"`
// FailingCaseIDs lists every case with Pass==false (including every
// harness-error case) — a report reader should never need to scan
// Cases by hand to find them.
FailingCaseIDs []string `json:"failing_case_ids"`
}
Report is one Run's full output.
func BuildReport ¶
func BuildReport(results []CaseResult, prov Provenance) Report
BuildReport aggregates a Run's []CaseResult into a Report.
type RunOptions ¶
type RunOptions struct {
// AskTopK/AskInsightM feed api.Server.WithAskConfig. Defaulted (see
// DefaultRunOptions) to comfortably exceed every fixture's corpus size
// so a fixture author does not have to reason about the production
// default (8) truncating an intentionally larger synthetic corpus.
AskTopK, AskInsightM int
RerankDefault bool
}
RunOptions configures Run. Zero value is DefaultRunOptions' shape.
func DefaultRunOptions ¶
func DefaultRunOptions() RunOptions
DefaultRunOptions returns the RunOptions every eval/ask/fixtures case in this repository is authored against.