classify

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT 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.

Documentation

Overview

Package classify implements the retention/segment classification pipeline for SMS, Gmail, and call documents: a deterministic Gate that short-circuits obvious cases and asymmetrically bounds the Jev-based Classifier's output, plus the Classifier itself (see classifier.go).

The Gate is intentionally asymmetric, not two mirrored checks:

  • BulkSender signals ("this looks like an automated/company sender") forbid promotion to retention=keep, because a bulk sender's messages are never worth indefinite retention even when Jev's segment classifier mistakes an automated notification for a personal one.
  • PersonSignal signals ("this looks like an ongoing human relationship") forbid demotion to retention=disposable, because deleting eligibility for a real conversation is a much worse failure mode than keeping a few extra low-value messages around.

Neither signal can hand back the OTHER's default outcome — flooring disposable to low is not the same as promoting to keep, and capping keep to low is not the same as demoting to disposable. See classifier.go's decideRetention for how these two flags combine with the Jev answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classifier

type Classifier struct {
	Jev *jev.Client
	// ConfidenceThreshold gates promotion to retention=disposable — see
	// decideRetention. Zero means defaultConfidenceThreshold (0.9).
	ConfidenceThreshold float64
}

Classifier turns a document + its deterministic Gate into a Result, calling Jev only when the Gate did not already fully decide the tag.

func (*Classifier) ClassifyDeterministic

func (c *Classifier) ClassifyDeterministic(gate Gate) *Result

ClassifyDeterministic returns the Result for a Gate whose Decided field is set. Callers must check gate.Decided != nil before calling this — it panics otherwise, since it indicates a caller-side logic error (deciding to skip Jev without actually having a decision).

func (*Classifier) ClassifyWithJev

func (c *Classifier) ClassifyWithJev(ctx context.Context, doc *model.Document, gate Gate) (*Result, int, error)

ClassifyWithJev calls Jev for doc and combines the answer with gate via decideRetention. Returns the Result, the input_tokens consumed by the call (for tick-level accounting), and an error when the Jev call itself failed or returned an unusable answer. It is the caller's responsibility to not call this when gate.Decided is already set.

func (*Classifier) JevEnabled

func (c *Classifier) JevEnabled() bool

JevEnabled reports whether the underlying Jev client is configured. The worker checks this before attempting any Jev-requiring classification.

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator computes Gate values for documents. It caches SenderLookup results for its own lifetime — callers MUST construct a new Evaluator per worker tick (see internal/worker/classification_worker.go) so the cache never serves data staler than "this tick's batch".

func NewEvaluator

func NewEvaluator(lookup SenderLookup) *Evaluator

NewEvaluator constructs an Evaluator. lookup may be nil, in which case SMS PersonSignal falls back to the contact_name-only check (no outbound-history query is made) — useful for tests and for any deployment that has not wired a document store dependency into the gate.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(ctx context.Context, doc *model.Document) (Gate, error)

Evaluate computes the Gate for doc. Only SourceSMS, SourceGmail, and SourceCall documents produce a non-empty Gate; any other source type returns the zero Gate (no signal, no decision).

type Gate

type Gate struct {
	// BulkSender indicates an automated/company sender. See package doc.
	BulkSender bool
	// PersonSignal indicates an ongoing human relationship. See package doc.
	PersonSignal bool
	// Decided is non-nil when a rule already fully determines the tag
	// without any Jev call — see classifier.go's Classify, which returns
	// immediately when this is set.
	Decided *Tag
}

Gate holds the deterministic signals computed for a single document.

type Result

type Result struct {
	Segment     string
	Retention   string
	Classifier  string // "rule" | "jev-latest"
	ClassifierP float64
	NeedsReview bool
	Gate        Gate
}

Result is a fully-determined classification, ready to be merged into a document's metadata by the caller (internal/worker.ClassificationWorker).

func (*Result) Metadata

func (r *Result) Metadata(classifiedAt time.Time) map[string]any

Metadata renders Result as the metadata fragment classification writes merge into documents.metadata (see spec: segment, retention, classifier, classifier_p, classified_at, needs_review, gate). classifiedAt is passed in rather than computed here so tests get deterministic output.

classifier_gate_checked_at is stamped alongside classified_at because producing a Result at all means the document's Gate has just been evaluated (Classifier.ClassifyDeterministic/ClassifyWithJev both require a Gate argument) — this is true whether the caller is ClassificationWorker.classifyOne tagging a previously-unclassified document for the first time, or recheckOne re-tagging a legacy document after finding a contradiction. Without this marker here, a document this method just tagged classifier="rule"/"jev-latest" would immediately re-enter internal/store.ListLegacyForRecheck's queue on the very next tick, since that query no longer excludes those two values by name (see listLegacyForRecheckQuery's doc comment) — only the marker, not the classifier value, stops the requeue.

type SenderLookup

type SenderLookup interface {
	HasOutboundTo(ctx context.Context, sender string) (bool, error)
}

SenderLookup answers whether the user has ever sent an outbound SMS to a given sender — the strongest available signal that a 010-prefixed number belongs to a real ongoing relationship rather than a one-off contact. *store.DocumentStore satisfies this via HasOutboundTo.

type Tag

type Tag struct {
	Segment   string
	Retention string
}

Tag is a fully-determined classification, produced by a deterministic rule rather than a Jev call.

Jump to

Keyboard shortcuts

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