eval

package
v2.62.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package eval is a retrieval-quality evaluation harness for CortexDB. It runs a labeled query set against a retriever and reports standard information- retrieval metrics (recall@k, precision@k, MRR, nDCG@k), so retrieval quality is measured and regression-guarded rather than assumed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NDCGAtK

func NDCGAtK(retrieved, relevant []string, k int) float64

NDCGAtK is the normalized discounted cumulative gain at k, with binary relevance. Returns 0 when there are no relevant documents.

func PrecisionAtK

func PrecisionAtK(retrieved, relevant []string, k int) float64

PrecisionAtK is the fraction of the top k retrieved documents that are relevant. Returns 0 when k <= 0.

func RecallAtK

func RecallAtK(retrieved, relevant []string, k int) float64

RecallAtK is the fraction of relevant documents retrieved within the top k. Returns 0 when there are no relevant documents.

func ReciprocalRank

func ReciprocalRank(retrieved, relevant []string) float64

ReciprocalRank is 1/rank of the first relevant document (rank starting at 1), or 0 if none is retrieved. Averaged across queries this is MRR.

Types

type Dataset

type Dataset struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Documents   []Document `json:"documents"`
	Queries     []Query    `json:"queries"`
}

Dataset is a corpus plus a labeled query set.

func Builtin

func Builtin() (*Dataset, error)

Builtin returns the bundled retrieval-quality dataset.

func Parse

func Parse(data []byte) (*Dataset, error)

Parse decodes a Dataset from JSON and validates referential integrity: every query's relevant ids must exist as documents.

type Document

type Document struct {
	ID      string `json:"id"`
	Title   string `json:"title"`
	Content string `json:"content"`
}

Document is one corpus document to index.

type Query

type Query struct {
	ID       string   `json:"id"`
	Text     string   `json:"text"`
	Relevant []string `json:"relevant"`
}

Query is one labeled query: its text plus the ids of relevant documents.

type QueryResult

type QueryResult struct {
	QueryID   string   `json:"query_id"`
	Retrieved []string `json:"retrieved"`
	RR        float64  `json:"rr"`
}

QueryResult is a single query's retrieval and its reciprocal rank.

type Report

type Report struct {
	Dataset      string          `json:"dataset"`
	NumQueries   int             `json:"num_queries"`
	Ks           []int           `json:"ks"`
	RecallAtK    map[int]float64 `json:"recall_at_k"`
	PrecisionAtK map[int]float64 `json:"precision_at_k"`
	NDCGAtK      map[int]float64 `json:"ndcg_at_k"`
	MRR          float64         `json:"mrr"`
	PerQuery     []QueryResult   `json:"per_query,omitempty"`
}

Report holds aggregate metrics over a query set, plus per-query detail.

func Run

func Run(ctx context.Context, ds *Dataset, r Retriever, ks ...int) (*Report, error)

Run evaluates a retriever over the dataset at the given cutoffs. It retrieves max(ks) results per query once and computes every metric from that ranking.

func (*Report) Summary

func (r *Report) Summary() string

Summary renders the aggregate metrics as a stable, human-readable block.

type Retriever

type Retriever interface {
	Retrieve(ctx context.Context, query string, k int) ([]string, error)
}

Retriever returns document ids ranked most-relevant first for a query. It is the single seam the harness needs; wire any CortexDB retrieval path (lexical, vector, graph, hybrid) behind it.

type RetrieverFunc

type RetrieverFunc func(ctx context.Context, query string, k int) ([]string, error)

RetrieverFunc adapts a function to Retriever.

func (RetrieverFunc) Retrieve

func (f RetrieverFunc) Retrieve(ctx context.Context, query string, k int) ([]string, error)

Jump to

Keyboard shortcuts

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