contradict

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package contradict classifies a pair of durable memory texts without an LLM: is the new write a restatement of the old fact (corroborate it), an update that contradicts it (the old fact is now stale), or a distinct claim (do nothing)? Embedding similarity cannot make this call — a value swap ("TTL is 10 minutes" → "TTL is 15 minutes") embeds in the same band as a restatement (measured in bench/dedup_test.go) — so this is a lexical differ in the tradition of de Marneffe et al. (ACL 2008): only the surface-detectable contradiction classes (changed value slot, flipped polarity) are in scope, and anything ambiguous is deliberately not an Update. Precision-first: the costly error is flagging a restatement as an update, which both downranks a live fact and loses its corroboration.

Index

Constants

This section is empty.

Variables

View Source
var Default = Config{OverlapFloor: 0.5, ResidueMax: 2, NegOverlapFloor: 0.6, AliasPrefixMin: 4}

Default is the shipped configuration, priced in bench/contradiction_test.go.

Functions

This section is empty.

Types

type Class

type Class int

Class is the detector's verdict on a (new, old) memory pair.

const (
	// Distinct means different claims: the pair shares too little to compare.
	Distinct Class = iota
	// Restatement means the same claim reworded: the old fact is re-observed.
	Restatement
	// Update means the new text contradicts the old: same subject and
	// attribute, but a changed value or flipped polarity.
	Update
)

func (Class) String

func (c Class) String() string

type Config

type Config struct {
	// OverlapFloor is the minimum shared-content overlap coefficient
	// (|A∩B| / min(|A|,|B|)) for the pair to be about the same claim at all.
	OverlapFloor float64
	// ResidueMax caps the non-value differing content tokens per side for a
	// value swap (and on the new side for a polarity flip): more residue means
	// the texts differ in substance, not just in one slot.
	ResidueMax int
	// NegOverlapFloor is the minimum containment of the new text in the old
	// (|A∩B| / |A|) for the polarity trigger: a genuine retraction talks about
	// the things the old fact mentions, and little else.
	NegOverlapFloor float64
	// AliasPrefixMin treats two differing value tokens as aliases of one name
	// when one is a prefix of the other and the shorter is at least this long
	// ("postgres"/"postgresql" yes, "go"/"golang" no).
	AliasPrefixMin int
}

Config holds the detector's decision thresholds. The zero value is unusable; start from Default. Fields are exported so the bench can sweep them.

type Result

type Result struct {
	Class  Class
	Reason string
}

Result is a classification with the evidence that produced it, for merge hints, logs, and bench audits.

func Classify

func Classify(newText, oldText string, cfg Config) Result

Classify labels newText against oldText. It never returns Update without a shared topical anchor plus a decisive differing value or polarity cue.

Jump to

Keyboard shortcuts

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