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 ¶
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 ¶
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 SearchChatsArm ¶
SearchChatsArm is arm B: today's search_chats and read_chat with a chat:read grant.
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.
type KindScore ¶
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.
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 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.
type SourcesFunc ¶
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.