bench

package
v0.0.0-...-cae0269 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 34 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 bench runs the team memory eval against a corpus that is already loaded into a database. The judged test, and later the platform-admin eval runs, share it: arms expose memory tools to an answering agent, Run asks every question and grades the answers with a judge model, and Report holds the per model and per arm scores.

Index

Constants

View Source
const (
	// DefaultEmbeddingModel and defaultEmbeddingDimensions match the business
	// memory store, so a win here can reuse that setup rather than a new one.
	DefaultEmbeddingModel = "perplexity/pplx-embed-v1-0.6b"
)

Variables

View Source
var DefaultMemoryModels = MemoryModels{Summary: chat.SummaryModel, Digest: activities.MemoryDigestModel}

DefaultMemoryModels are the models the live summary and digest jobs use.

Functions

This section is empty.

Types

type Arm

type Arm struct {
	Name   string
	Search func(ctx context.Context, query string) (ArmResult, error)
	Sweep  func(ctx context.Context) (ArmResult, error)

	Tools        []Tool
	Call         func(ctx context.Context, tool, arguments string) (string, error)
	Instructions string

	// Sources resolves memo and digest citations to their source chats so
	// they can be checked. Nil for arms whose tools only return chats.
	Sources SourcesFunc
}

Arm is one way of giving an agent memory. Search runs a keyword query over the main project's full history; Sweep probes what the arm shows for the main project, for leak and isolation checks. An arm with a browse mode sweeps everything; an arm without one (search_team_memory is search only) probes with every term the corpus plants: evidence, titles, canaries and secrets. So a sweep is exhaustive for planted content, not for arbitrary text a summary might invent. Tools, Call and Instructions are what the judged eval gives the answering agent. Every function carries its own principal and grants, so callers pass a plain context.

func HybridTeamMemoryArm

func HybridTeamMemoryArm(ctx context.Context, logger *slog.Logger, embedder Embedder, target Target) (Arm, error)

HybridTeamMemoryArm is arm E: search_team_memory with the same tool and arguments, but each query also runs a vector search over embeddings of the same masked items, and the two ranked lists are merged with reciprocal rank fusion. Items are embedded in memory when the arm is built, so the arm needs no schema change; it measures retrieval quality, not storage. Only masked text is embedded, so a vector can never encode a secret the summary job removed. Vector-only hits skip the read audit the tool writes; this is an eval arm, not a shipped path.

func NoMemoryArm

func NoMemoryArm() Arm

NoMemoryArm is arm A: the agent answers without tools.

func SearchChatsArm

func SearchChatsArm(logger *slog.Logger, target Target) (Arm, error)

SearchChatsArm is arm B: today's search_chats and read_chat with a chat:read grant.

func SearchTeamMemoryArm

func SearchTeamMemoryArm(logger *slog.Logger, target Target) (Arm, error)

SearchTeamMemoryArm is arm C: search_team_memory alone, with memory:read on the main project. It reads the summaries already stored on the target's chats, so callers write those first.

type ArmResult

type ArmResult struct {
	// Output is the exact text the tools returned, as an agent would see it.
	Output string

	// ChatIDs are the chats the returned items came from.
	ChatIDs []uuid.UUID
}

ArmResult is what one arm search or sweep returned.

type ArmScore

type ArmScore struct {
	Model string `json:"model"`
	Arm   string `json:"arm"`

	// HasTools is whether the arm gave the agent memory tools; citation rates
	// mean nothing for an arm without them.
	HasTools bool `json:"has_tools"`

	// AccuracyByRun is correct over graded answers for each run that graded
	// at least one answer; Accuracy is their mean. Errored answers and judge
	// failures are not graded, so API trouble shows up in Errors instead of
	// lowering accuracy, and a run with nothing graded is left out.
	AccuracyByRun []float64 `json:"accuracy_by_run"`
	Accuracy      float64   `json:"accuracy"`

	ByKind map[memoryeval.QuestionKind]KindScore `json:"by_kind"`

	// Answerable counts graded answers to questions that have an answer;
	// CitedAnswers of those cite at least one source and ValidCited cite only
	// sources that back the answer. A memo or digest citation backs it when
	// one of the chats it was built from is a source containing the answer;
	// when the arm can't resolve memos and digests, those citations are left
	// unchecked. MemoOrDigestCited counts answers that cite memos or digests.
	Answerable        int `json:"answerable"`
	CitedAnswers      int `json:"cited_answers"`
	ValidCited        int `json:"valid_cited"`
	MemoOrDigestCited int `json:"memo_or_digest_cited"`

	// Leaks names every planted secret that reached a tool result or answer;
	// IsolationViolations names every canary from another project or a
	// private session that did.
	Leaks               []string `json:"leaks"`
	IsolationViolations []string `json:"isolation_violations"`

	// NotFound counts negative questions answered "Not found" out of
	// Negatives graded.
	NotFound  int `json:"not_found"`
	Negatives int `json:"negatives"`

	ToolTokensPerQuestion int `json:"tool_tokens_per_question"`
	RetrievalMisses       int `json:"retrieval_misses"`
	ReasoningMisses       int `json:"reasoning_misses"`
	Errors                int `json:"errors"`
	Answers               int `json:"answers"`

	PromptTokens     int     `json:"prompt_tokens"`
	CompletionTokens int     `json:"completion_tokens"`
	CostUSD          float64 `json:"cost_usd"`
	LatencyMeanMS    int64   `json:"latency_mean_ms"`
	LatencyP95MS     int64   `json:"latency_p95_ms"`
}

ArmScore aggregates one answer model in one arm across runs.

type Config

type Config struct {
	// AnswerModels each answer every question in every arm, so a run compares
	// models as well as arms.
	AnswerModels []string

	// JudgeModel grades every answer. It must differ from every answering
	// model so the judge does not favor its own phrasing.
	JudgeModel string

	// Runs repeats each model and arm so results carry a range, not one
	// sample.
	Runs int

	// Concurrency bounds in-flight questions across models, arms and runs.
	Concurrency int
}

Config is what one eval run varies.

func (Config) Validate

func (c Config) Validate() error

Validate rejects a config that would grade a model with itself or call a model the completion client does not allow.

type Embedder

type Embedder interface {
	Embed(ctx context.Context, inputs []string) ([][]float32, error)
}

Embedder turns texts into vectors, one per input, in order.

type KindScore

type KindScore struct {
	Correct int `json:"correct"`
	Total   int `json:"total"`
}

KindScore counts correct over graded answers for one question kind, summed across runs.

type MemoryModels

type MemoryModels struct {
	// Summary writes each chat's masked summary.
	Summary string `json:"summary_model"`

	// Digest writes the day, week and month digests.
	Digest string `json:"digest_model"`
}

MemoryModels are the models that write what team memory reads.

type ModelSpend

type ModelSpend struct {
	Model            string  `json:"model"`
	Calls            int     `json:"calls"`
	PromptTokens     int     `json:"prompt_tokens"`
	CompletionTokens int     `json:"completion_tokens"`
	CostUSD          float64 `json:"cost_usd"`

	// Unpriced counts calls whose response reported no cost; CostUSD leaves
	// them out, so a nonzero count means the cost is a lower bound.
	Unpriced int `json:"unpriced_calls"`
}

ModelSpend is what one model's completions cost during a step.

type OpenRouterEmbedder

type OpenRouterEmbedder struct {
	Client         openrouter.CompletionClient
	OrganizationID string
	Model          string
	Dimensions     int
}

OpenRouterEmbedder embeds through the OpenRouter completion client.

func NewOpenRouterEmbedder

func NewOpenRouterEmbedder(client openrouter.CompletionClient, organizationID, model string) OpenRouterEmbedder

NewOpenRouterEmbedder embeds with the business memory model unless model is set.

func (OpenRouterEmbedder) Embed

func (e OpenRouterEmbedder) Embed(ctx context.Context, inputs []string) ([][]float32, error)

Embed implements Embedder in batches.

type Preparation

type Preparation struct {
	Models    MemoryModels `json:"models"`
	Summaries int          `json:"summaries"`
	Failed    int          `json:"failed_summaries"`
	Digests   int          `json:"digests"`

	SummarySpend ModelSpend `json:"summary_spend"`
	DigestSpend  ModelSpend `json:"digest_spend"`
	Duration     int64      `json:"duration_ms"`
}

Preparation is what writing team memory for a target did and cost.

func Prepare

func Prepare(ctx context.Context, logger *slog.Logger, client openrouter.CompletionClient, target Target, models MemoryModels, concurrency int) (Preparation, error)

Prepare writes team memory for the target with the given models, the way the live jobs would: a masked summary for every team chat, placed on the day its chat ended, then day, week and month digests as of the corpus's now. Private sessions get no summary, as in the live sweep. Existing summaries and digests for the target are replaced, so runs with different models do not mix.

type Project

type Project struct {
	ID   uuid.UUID
	Slug string
}

Project is the stored identity of one corpus project.

type RecallReport

type RecallReport struct {
	Rows []RecallRow `json:"rows"`
}

RecallReport compares how often each arm's search returns an answerable question's source chats, with no answering agent or judge involved, so it isolates retrieval from answering.

func QuestionRecall

func QuestionRecall(ctx context.Context, corpus *memoryeval.Corpus, arms []Arm) (RecallReport, error)

QuestionRecall searches each arm for every answerable question with each of its evidence groups, pooling the results, and once with the question's text.

func (RecallReport) Markdown

func (r RecallReport) Markdown() string

Markdown renders the recall table.

type RecallRow

type RecallRow struct {
	Arm string `json:"arm"`

	// Questions is how many answerable questions were asked.
	Questions int `json:"questions"`

	// Keyword counts questions whose sources all came back across searches on
	// its evidence groups: the query an agent writes when it knows the words.
	Keyword int `json:"keyword_retrieved"`

	// Natural counts questions whose sources all came back when the
	// question's own text was the query: the query an agent writes when it
	// does not know which words the team used.
	Natural int `json:"natural_retrieved"`
}

RecallRow is one arm's retrieval on the answerable questions.

type Report

type Report struct {
	JudgeModel string    `json:"judge_model"`
	Runs       int       `json:"runs"`
	Questions  int       `json:"questions"`
	StartedAt  time.Time `json:"started_at"`
	FinishedAt time.Time `json:"finished_at"`

	// Scores has one entry per answer model and arm, in config order.
	Scores []ArmScore `json:"scores"`

	// JudgeCostUSD is what grading cost across the run.
	JudgeCostUSD float64 `json:"judge_cost_usd"`

	// Preparation is how team memory was written before the arms ran, when
	// the caller prepared it; arms that read summaries or digests depend on
	// its models.
	Preparation *Preparation `json:"preparation,omitempty"`
}

Report is the scored outcome of one eval run. It is plain data so it can be stored and rendered by the dashboard as well as printed as markdown.

func Run

func Run(ctx context.Context, client openrouter.CompletionClient, corpus *memoryeval.Corpus, arms []Arm, cfg Config) (*Report, error)

Run asks every question with every answer model in every arm cfg.Runs times, grades every answer and scores the results. It fails only when the setup is broken: every answer or every grading call erroring.

func (*Report) Markdown

func (r *Report) Markdown() string

Markdown renders the report as one table row per answer model and arm.

type SourcesFunc

type SourcesFunc func(ctx context.Context, kind string, id uuid.UUID) ([]uuid.UUID, error)

SourcesFunc returns the chats a memo or digest citation stands for, so the citation can be checked against a question's sources.

func MemorySources

func MemorySources(target Target) SourcesFunc

MemorySources resolves memo citations to the chat they were saved from and digest citations to every chat they were built from, walking week and month digests down to their day digests.

type Target

type Target struct {
	DB             *pgxpool.Pool
	Corpus         *memoryeval.Corpus
	OrganizationID string

	// Projects maps corpus projects to their stored rows.
	Projects map[memoryeval.ProjectKey]Project

	// UserID maps a corpus user handle to its stored user ID.
	UserID func(handle string) string
}

Target is a corpus loaded into one organization.

type Tool

type Tool struct {
	Name        string
	Description string

	// Schema is the JSON Schema of the tool's arguments.
	Schema string
}

Tool is one tool an arm offers the answering agent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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