eval

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eval implements the OKF held-out retrieval evaluation: it derives example-query/expected-document pairs from a bundle, builds a held-out copy of the corpus with those queries stripped from their host chunks, ingests the copy into an ephemeral database, runs each query through the Retriever, and computes doc-level retrieval metrics against a versioned baseline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunGraphInclusion added in v0.3.0

func RunGraphInclusion(ctx context.Context, logger *slog.Logger, opts GraphOptions) (GraphMetrics, []GraphCaseResult, error)

RunGraphInclusion ingests the bundle as-is (answers stay in place, links captured), runs each curated query through the lexical retriever, and measures whether the expected answer document is found directly (top-K) versus reachable through the 1-hop link neighborhood of the top seeds (what neighborhood injection surfaces). The user's real database is never touched. It returns the aggregate metrics and the per-case results.

Types

type GraphCase added in v0.3.0

type GraphCase struct {
	Query       string `json:"query"`
	ExpectedURI string `json:"expected_uri"`
	Note        string `json:"note,omitempty"`
}

GraphCase is one curated graph-answerability example: a natural-language query whose best lexical match is a hub/overview document, and the expected answer document that is reachable from that hub by a link rather than by keywords.

type GraphCaseResult added in v0.3.0

type GraphCaseResult struct {
	Query       string
	ExpectedURI string
	DirectHit   bool
	Included    bool
	GraphHit    bool
	Seeds       []string
}

GraphCaseResult is the per-case outcome, surfaced so the report and tests can show exactly which cases injection recovered.

type GraphMetrics added in v0.3.0

type GraphMetrics struct {
	N                 int     `json:"n"`
	K                 int     `json:"k"`
	SeedDepth         int     `json:"seed_depth"`
	DirectHitAtK      float64 `json:"direct_hit_at_k"`
	NeighborInclusion float64 `json:"neighbor_inclusion"`
	Lift              float64 `json:"lift"`
	RecoveredMisses   float64 `json:"recovered_misses"`
	// GraphHitAtK is the fraction of cases where the actual GraphRetriever (base +
	// link expansion) returns the expected document in its top-K. It is the real
	// Phase 2 measurement; NeighborInclusion is the raw-neighborhood proxy above.
	GraphHitAtK float64 `json:"graph_hit_at_k"`
}

GraphMetrics holds the graph-answerability scores over all cases. Rates are in [0,1]. DirectHitAtK is what plain lexical search achieves; NeighborInclusion is what read/context neighborhood injection would achieve (the answer is in the top-K OR in the 1-hop neighborhood of the top seeds); Lift is the value injection adds; RecoveredMisses is, of the cases plain search misses, the fraction injection recovers.

func ReportGraph added in v0.3.0

func ReportGraph(ctx context.Context, logger *slog.Logger, out io.Writer, opts GraphOptions) (GraphMetrics, error)

ReportGraph runs a graph-answerability evaluation and renders the metrics plus a per-case breakdown to out. It returns the computed metrics.

type GraphOptions added in v0.3.0

type GraphOptions struct {
	Bundle    string
	K         int
	SeedDepth int
	Include   []string
	Exclude   []string
	Chunking  chunk.Config
}

GraphOptions configures a graph-answerability run. Bundle is the OKF bundle (which must contain a cases.json). K is the lexical retrieval depth used both for the direct-hit measurement and as the seed pool whose neighbors are expanded; SeedDepth caps how many of the top-K hits are expanded. Include / Exclude / Chunking mirror the ingest configuration.

type Metrics

type Metrics struct {
	N          int     `json:"n"`
	HitAt1     float64 `json:"hit_at_1"`
	RecallAtK  float64 `json:"recall_at_k"`
	MRRAtK     float64 `json:"mrr_at_k"`
	ExactChunk float64 `json:"exact_chunk"`
	K          int     `json:"k"`
}

Metrics holds the doc-level retrieval scores over all evaluated pairs. All rates are in [0,1]. N is the number of example-query pairs evaluated.

func Report

func Report(ctx context.Context, logger *slog.Logger, out io.Writer, opts Options, baselinePath string, save bool) (Metrics, error)

Report runs an evaluation and renders the metrics table to out, loading the baseline at baselinePath for delta annotation when present and saving the fresh metrics back when save is true. It returns the computed Metrics so callers can reuse them.

func Run

func Run(ctx context.Context, logger *slog.Logger, opts Options) (Metrics, error)

Run executes the full held-out evaluation: derive example-query pairs, build a held-out copy with those queries stripped, ingest the copy into an ephemeral SQLite database, search each query, and compute doc-level metrics. The user's real database is never touched — everything happens under a temp directory that is removed on return. The Retriever is the FTS5 engine over the temp DB.

type Options

type Options struct {
	Bundle   string
	K        int
	Include  []string
	Exclude  []string
	Chunking chunk.Config
	// Semantic, when true, evaluates the hybrid (bm25 + vector) retriever instead
	// of the lexical engine, so the run can be compared against the FTS baseline.
	Semantic bool
	// ModelDir is the embedding model directory used when Semantic is true.
	ModelDir string
	// GraphExpansion, when true, wraps the retriever with link-neighbor expansion,
	// so the held-out metrics measure the effect of Phase 2 (the gate: recall up,
	// Hit@1/MRR not down). Seed depth / decay default when their fields are unset.
	GraphExpansion bool
	GraphSeedDepth int
	GraphDecay     float64
}

Options configures one evaluation run. Bundle is the path to the OKF bundle. K is the retrieval depth (defaults to 12). Include/Exclude/Chunking mirror the ingest configuration so the held-out copy is indexed exactly like production.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL