memoryeval

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: 8 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.

README

Team memory eval

Synthetic corpus, questions and checks for team chat memory in the Platform MCP.

  • Corpus (Build): 4 users, 150 chats over 60 days in the main project (25 decisions, 8 reversals, 22 timeline chats across 8 timelines, 10 planted secrets, 3 private sessions) plus a 12-chat second project. Chat IDs are derived from chat keys.
  • Questions: 55, each with an answer key. Answerable questions also name their source chats and the evidence terms a source must contain; the 5 negative and 5 isolation questions expect "Not found" and have neither. The hard set has 7 temporal questions (what was true when another event happened) and 8 syntheses. Each needs three or more chats at least two weeks apart and shares no keywords with them, which TestHardQuestionsShareNoKeywordsWithSources enforces, so rewriting the question into a keyword search still leaves the agent to find and order several chats over time.
  • Mechanical checks (CI, every PR): TestSearchChatsBaselineMechanical loads the corpus into Postgres and probes the search_chats baseline. It asserts no credential leaks, no other-project results and full retrieval of source chats, and logs the remaining leaks, private-session hits and estimated tool tokens. The PRs that add arms C and D will add their own probes and the recall size assertion.
  • Judged accuracy (on demand, costs LLM calls): mise run eval:memory answers every question with each arm's tools, grades answers with a judge model that differs from the answering model, and prints a report. Set OPENROUTER_DEV_KEY first; --runs, --models and --out are optional. --models takes a comma separated list of answering models, and the report has one row per model and arm with accuracy, tokens, cost and latency, so a run can compare models as well as arms. Before the arms run, bench.Prepare writes every team chat's masked summary and the day, week and month digests with --summary-model and --digest-model (defaults: the live jobs' models), and the report shows what that cost, so summary and digest models can be compared too. Existing summaries and digests for the target are replaced on each run, so never point it at a database whose memory you need to keep.
  • Runner (bench): arms, the agent loop, judging and scoring live in a plain package that takes a corpus already loaded into a database, so the tests and future scheduled runs share one implementation.

Arms: A has no memory tools, B is today's search_chats and read_chat. Arms C (search_team_memory) and D (recall_team_history + zoom + search_team_memory) are added by the PRs that ship those tools. Arm E is search_team_memory with hybrid retrieval: the same masked items are embedded in memory (--embedding-model, default the business memory model) and each query fuses the vector ranks with the full-text ranks (reciprocal rank fusion). It needs no schema change. Its results on this synthetic corpus inform, rather than settle, whether team memory needs embeddings. The judged report adds a retrieval recall table for arms C and E, querying with evidence words and with each question's own text, so retrieval can be compared without the answering agent.

Planned rollout criterion, once arm D lands: Organizational Memory is enabled for customers (the staff admin Business Memory Extraction toggle) only when arm D meets every gate. Nothing in this package evaluates the gates yet; read them off the report.

  • Complete run: no errored answers in either arm, since errors drop out of the graded rates below (accuracy, citations, negatives) while still adding to tool tokens per question.
  • Hard-set lift: at least 15 points above arm B on the hard set.
  • Overall accuracy: at least 80%, and no lower than arm B.
  • Privacy: no leaked secret, and nothing from another project or a private session.
  • Citations: valid sources at least 95% of the time.
  • Negatives: at least 4 of 5 answered "Not found".
  • Tokens: recall block under 8k tokens, and tool tokens per question at most twice arm B's.

Documentation

Overview

Package memoryeval holds the synthetic corpus, question set and mechanical checks used to evaluate team chat memory in the Platform MCP.

The corpus is a fictional freight software team: four users, about 150 chats over 60 days in a main project, three private sessions, and a second project. It plants decisions, reversals and secrets so that answers can be graded and leaks or isolation failures can be detected by exact match. It is plain data with deterministic chat IDs, so every run sees the same corpus and citations can be traced back to it.

Index

Constants

View Source
const (
	// RoleUser marks a message written by a person.
	RoleUser = "user"

	// RoleAssistant marks a message written by the agent.
	RoleAssistant = "assistant"
)
View Source
const NotFound = "Not found: nothing in the project's team history answers this."

NotFound is the answer key for questions memory must not answer.

Variables

This section is empty.

Functions

func ChatID

func ChatID(key string) uuid.UUID

ChatID is the deterministic chat ID for a corpus key.

func EstimateTokens

func EstimateTokens(text string) int

EstimateTokens approximates the token count of text.

Types

type Chat

type Chat struct {
	// Key is the stable corpus key questions use to name their sources.
	Key string

	// ID is derived from Key and is what loaders store as the chat ID.
	ID uuid.UUID

	// Project is the project the chat belongs to.
	Project ProjectKey

	// Owner is the handle of the user who ran the session.
	Owner string

	// Title is the chat title.
	Title string

	// Private marks a session that must never reach team memory.
	Private bool

	// Canaries are phrases unique to this chat. They are set only on chats
	// that team memory for ProjectMain must never surface.
	Canaries []string

	// Messages alternate between user and assistant, starting with the user.
	Messages []Message
}

Chat is one synthetic chat session.

func (Chat) Isolated

func (c Chat) Isolated() bool

Isolated reports whether team memory for ProjectMain must never surface this chat.

func (Chat) StartedAt

func (c Chat) StartedAt() time.Time

StartedAt is when the first message was sent.

func (Chat) Text

func (c Chat) Text() string

Text joins the title and every message, for evidence and canary matching.

type Corpus

type Corpus struct {
	// Now anchors every timestamp; history runs from Now back 60 days.
	Now time.Time

	// Users are the four team members.
	Users []User

	// Chats are all chats in both projects, oldest first.
	Chats []Chat

	// Secrets are the planted sensitive values, one per masking rule.
	Secrets []Secret

	// Questions are the 55 graded questions.
	Questions []Question
}

Corpus is the full synthetic dataset.

func Build

func Build(now time.Time) *Corpus

Build returns the corpus anchored at now. The same now always yields the same corpus.

func (*Corpus) Chat

func (c *Corpus) Chat(key string) (Chat, bool)

Chat returns the chat with the given key.

func (*Corpus) ChatByID

func (c *Corpus) ChatByID(id uuid.UUID) (Chat, bool)

ChatByID returns the chat with the given ID.

func (*Corpus) ChatCitationValid

func (c *Corpus) ChatCitationValid(q Question, chatID uuid.UUID) bool

ChatCitationValid reports whether citing chatID for q is valid: the chat is one of the question's sources, a team chat in the main project, and it contains the answer's evidence. Requiring a source rules out superseded decisions that merely mention the current answer.

func (*Corpus) IsolationViolations

func (c *Corpus) IsolationViolations(output string) []string

IsolationViolations returns the canaries from private sessions and the other project that appear in output, ignoring case.

func (*Corpus) Leaks

func (c *Corpus) Leaks(output string) []Secret

Leaks returns the planted secrets that appear in output. Matching ignores case and separators, so a card number without its spaces or a phone number with different punctuation still counts.

func (*Corpus) WithChatIDs

func (c *Corpus) WithChatIDs(id func(key string) uuid.UUID) *Corpus

WithChatIDs returns a copy of the corpus whose chats carry the IDs id returns for their keys. Questions name chats by key, so answer keys and citation checks still hold. A loader that shares a database with other tenants, such as the demo seed, uses it to keep chat IDs unique.

type Message

type Message struct {
	// Role is RoleUser or RoleAssistant.
	Role string

	// Text is the message content, with secrets already substituted.
	Text string

	// At is when the message was sent.
	At time.Time
}

Message is one chat message.

type ProjectKey

type ProjectKey string

ProjectKey names one of the corpus projects. Loaders map it to a real project.

const (
	// ProjectMain is the project whose memory is under evaluation.
	ProjectMain ProjectKey = "main"

	// ProjectOther is a second project in the same organization. None of its
	// content may appear in answers about ProjectMain.
	ProjectOther ProjectKey = "other"
)

type Question

type Question struct {
	// ID is a stable identifier such as q01.
	ID string

	// Kind is what the question tests.
	Kind QuestionKind

	// Text is what the answering agent is asked.
	Text string

	// Answer is the answer key the judge grades against.
	Answer string

	// Sources are the keys of the chats the answer comes from. Empty when the
	// expected answer is NotFound.
	Sources []string

	// Evidence lists groups of terms. A cited chat, memo or digest supports
	// the answer when it contains every term of at least one group.
	Evidence [][]string
}

Question is one graded question about the main project.

func (Question) ExpectsNotFound

func (q Question) ExpectsNotFound() bool

ExpectsNotFound reports whether the correct answer is NotFound.

func (Question) Supports

func (q Question) Supports(text string) bool

Supports reports whether text contains every term of at least one evidence group, ignoring case.

type QuestionKind

type QuestionKind string

QuestionKind groups questions by what they test.

const (
	// QuestionPointLookup asks for one decision.
	QuestionPointLookup QuestionKind = "point_lookup"

	// QuestionTimeline asks for changes across several sessions, in order.
	QuestionTimeline QuestionKind = "timeline"

	// QuestionReversal asks for the current state of a decision that changed.
	QuestionReversal QuestionKind = "reversal"

	// QuestionNegative asks about something the team never discussed.
	QuestionNegative QuestionKind = "negative"

	// QuestionIsolation asks about something that exists only in a private
	// session or in the other project.
	QuestionIsolation QuestionKind = "isolation"

	// QuestionTemporal asks what was true at the moment of another event, so
	// the answer needs the anchor event, the decision in force then and the
	// later change, which sit weeks apart.
	QuestionTemporal QuestionKind = "temporal"

	// QuestionSynthesis needs facts from three or more chats spread over
	// weeks.
	QuestionSynthesis QuestionKind = "synthesis"
)

func (QuestionKind) Hard

func (k QuestionKind) Hard() bool

Hard reports whether the kind is in the hard set. Hard questions share no keywords with their sources and need several chats far apart in time.

type Secret

type Secret struct {
	// Name is the placeholder chats use, written as {{secret:<name>}}.
	Name string

	// Category is the masking category the value falls under.
	Category SecretCategory

	// Value is the generated sensitive value.
	Value string
}

Secret is a planted sensitive value. Memory must never return Value.

type SecretCategory

type SecretCategory string

SecretCategory is the risk-masking category a planted value belongs to.

const (
	// SecretCategoryCredential is a credential that secret scanning detects.
	SecretCategoryCredential SecretCategory = "secret"

	// SecretCategoryPII is personal contact data.
	SecretCategoryPII SecretCategory = "pii"

	// SecretCategoryFinancial is payment card data.
	SecretCategoryFinancial SecretCategory = "financial"

	// SecretCategoryGovernmentID is a government-issued identifier.
	SecretCategoryGovernmentID SecretCategory = "government_ids"

	// SecretCategoryHealthcare is a medical record identifier.
	SecretCategoryHealthcare SecretCategory = "healthcare"
)

type User

type User struct {
	// Handle is a short stable identifier that loaders turn into user IDs.
	Handle string

	// Name is the display name.
	Name string
}

User is a synthetic team member.

Directories

Path Synopsis
Package bench runs the team memory eval against a corpus that is already loaded into a database.
Package bench runs the team memory eval against a corpus that is already loaded into a database.
Package evalrun runs one stored team memory eval run against the corpus the demo seed wrote: it rebuilds the corpus, writes team memory with the run's summary and digest models, scores every answer model in every arm, and stores the report on the run's row.
Package evalrun runs one stored team memory eval run against the corpus the demo seed wrote: it rebuilds the corpus, writes team memory with the run's summary and digest models, scores every answer model in every arm, and stores the report on the run's row.

Jump to

Keyboard shortcuts

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