exemplars

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package exemplars implements BM25-based few-shot exemplar mining with greedy-diverse k-center selection. It maintains per-task JSONL sidecars of verified-good (input, output) pairs and, on demand, selects a diverse ~50 finalists subset and persists it for fast retrieval.

Concurrency: Append uses O_APPEND for cross-process safety plus an in-process mutex per task file. Select and Retrieve are read-only after the selected.json is written and safe to call concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(dir, task, paramsKey, input string, output []byte, margin float64) error

Append appends a verified-good (input, output) pair to the per-task sidecar. It is concurrency-safe across goroutines (mutex) and across processes (O_APPEND).

func Select

func Select(dir, task string) (string, error)

Select builds a BM25 index over the sidecar for `task`, then runs a greedy k-center diverse pick targeting ~50 finalists, and writes the result to <dir>/<task>.selected.json. It returns a human-readable report.

Types

type Pair

type Pair struct {
	Input     string  `json:"input"`
	Output    string  `json:"output"`
	ParamsKey string  `json:"params_key,omitempty"`
	Margin    float64 `json:"margin,omitempty"`
}

Pair is one exemplar stored in the sidecar or returned by Retrieve.

func Retrieve

func Retrieve(dir, task, input string, k int) []Pair

Retrieve loads <dir>/<task>.selected.json, BM25-ranks the entries against `input`, and returns the top-k diverse results. Never errors; missing file or any I/O issue returns nil.

Jump to

Keyboard shortcuts

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