evidence

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 11 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

Explicit evidence relationships

This is an opt-in SQLite projection; [evidence] mode = "off" remains the product default. shadow captures sources and traces direct relationships without changing context output. on additionally groups validated sources. No LLM or new relevance weights are used. Existing qualification remains intact. max_related_nodes = 24 bounds direct edges inspected per query, matching the existing deduplicated candidate bound. Values 1..512 are resource bounds, not a claim about the best recall setting. Zero selects 24. There is no graph walk.

Native reply relationships and actual generator source_refs are captured when events/derived memories are written. A complete ordered import is labeled ordered_source, distinct from native_ref. Timestamps never establish a reply. Coarse generator provenance is available for inspection, but does not force an entire session's sources into a prompt. Exact source bundles require explicit retained spans. Relations never certify that a source or its answer is true.

Structured source and correction inputs

Use existing authenticated /api/v1/events/batch ingestion and the usual project/session/device envelope. Source documents use source.document_captured with content, url and/or path, optional git_commit, git_blob, captured_at, and complete (false means a retained excerpt). No URL is fetched. The source version is SHA256 of canonical retained UTF-8 bytes (CRLF/CR to LF; spaces and Unicode forms unchanged). An empty body is locator_only.

evidence.link_asserted has this payload contract:

relation: derived_from | supersedes
basis: explicit_assertion | model_inference
from, to:
  event_id OR object_id
  revision_sha: exact source version
  span: {start, end, sha256}      # half-open canonical UTF-8 byte range
scope:
  entity, attribute, environment # mandatory for supersedes
  qualifiers: {branch: ..., version: ...}  # optional, exact conditions
witnesses: [endpoint, ...]       # 1..16 retained source/version references

Corrections require exact spans on both endpoints. Scope is an explicit structured assertion by the emitting device; validation does not independently prove the prose entails that assertion. Missing scope remains a candidate, not a wildcard. model_inference always remains a candidate; clients cannot claim native/generator authority. Self links, wrong hashes or UTF-8 boundaries are invalid. References unavailable in the same project remain pending. Native source changes do not silently repair an invalid span after redaction.

Assertions arriving before endpoints are kept in evidence_inputs, with status and diagnostics. Each arriving event/object retries up to 256 matching pending inputs; this is an ingestion work bound, not a confidence threshold. Massive fan-in beyond that bound requires replaying the pending assertion events. evidence.link_retracted names assertion_event_id; its scoped tombstone works before the assertion arrives. Independent active observations are retained. Competing or cyclic corrections in the same scope become candidates. Resolving a conflict does not silently promote candidates: retract incorrect observations and submit a new explicit assertion. All original and frozen versions remain.

Query and inspection

on forms source bundles before the existing prompt/reply role suppression. The independently admitted anchor keeps its original content window and rank. Required companion endpoints/witnesses consume real source slots, and session diversity is preserved. A group is either delivered or removed as a whole by exclusions, item count and rendered character budget. A long/partial source is marked incomplete. Exact retained spans may be complete even if the original article is only retained in part; availability=excerpt stays visible. Corrections are labeled with their exact scope and dates; old values are never silently removed, so the answering agent can handle historical/as-of questions. No rule assumes "newest is true". Candidate/retracted/invalid links do not pack.

The context JSON includes evidence_groups only for delivered groups, with source/version IDs, required spans, relation basis/state and completeness. complete concerns the required retained sources, never all evidence for an answer. GET /api/v1/evidence/{object_id}?project_id=...&limit=24 requires the usual read authentication and returns the retained source, document locator, version, and direct links including inactive states. It does not traverse into other projects. GET /api/v1/evidence/assertions/{event_id}?project_id=... returns an assertion's pending/invalid/candidate/active/retracted status and diagnostic. Article content hashes do not prove a live URL is unchanged.

Measurement limitations

Default-off, ownership/version/idempotency/budget checks and shadow parity are covered by tests. The private real-library backfill validates preservation and native coverage; it is keyword-only and has no answer quality labels. New relations are experimental: no quality improvement is claimed until the same frozen dataset, answer/judge models, budgets and per-question protocol are run. Frozen old bodies absent before capture cannot be recovered. Current derived source versions are validated against actual memory/summary content/provenance. This does not automatically extract every correction from natural-language history or infer which source sentence supports each summary sentence.

Documentation

Overview

Package evidence maintains source-backed, versioned evidence relationships. Its projections never establish that a source statement is true.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonical

func Canonical(s string) string

func CurrentObjects

func CurrentObjects(ctx context.Context, db *sql.DB, owner, project string, seeds []Seed) (map[Seed]Object, error)

CurrentObjects batches reference lookup. It never reuses an obsolete derived version after memory/summary text or provenance changes while capture is off.

func DocumentLocator

func DocumentLocator(ctx context.Context, db *sql.DB, owner string, o Object) (map[string]string, error)

A locator is provenance metadata, never an instruction to fetch content.

func IndexEvent

func IndexEvent(ctx context.Context, tx *sql.Tx, id string) error

IndexEvent observes a committed-to-this-transaction raw source. Call after ingestion redaction, in the same transaction. Missing native refs stay absent until their endpoint arrives; nearest timestamps never fabricate a link.

func RecordDerived

func RecordDerived(ctx context.Context, tx *sql.Tx, d Derived) error

RecordDerived freezes the actual generated version and its declared sources. It records provenance, not semantic proof that every source supports a fact.

func SHA

func SHA(s string) string

func SpanText

func SpanText(body string, span *Span) (string, error)

func Text

func Text(ctx context.Context, db *sql.DB, owner string, o Object) (string, error)

Text resolves the exact stored source version and validates the content hash.

func WithPolicy

func WithPolicy(ctx context.Context, p Policy) context.Context

Types

type Assertion

type Assertion struct {
	Relation  string     `json:"relation"`
	From      Endpoint   `json:"from"`
	To        Endpoint   `json:"to"`
	Scope     Scope      `json:"scope"`
	Witnesses []Endpoint `json:"witnesses"`
	// Only explicit_assertion and model_inference are accepted from clients.
	// Neither is promoted into native_ref or a claim of factual correctness.
	Basis string `json:"basis"`
}

type Derived

type Derived struct {
	Kind, Ref, Project, Session, Title, Content string
	Sources                                     []SourceRef
	At                                          time.Time
}

type Detail

type Detail struct {
	Object      Object            `json:"object"`
	Text        string            `json:"text"`
	SourceError string            `json:"source_error,omitempty"`
	Links       []Link            `json:"links"`
	Locator     map[string]string `json:"locator,omitempty"`
}

func Inspect

func Inspect(ctx context.Context, db *sql.DB, owner, project, id string, limit int) (Detail, error)

type Endpoint

type Endpoint struct {
	ObjectID string `json:"object_id,omitempty"`
	EventID  string `json:"event_id,omitempty"`
	Revision string `json:"revision_sha"`
	Span     *Span  `json:"span,omitempty"`
}
type Link struct {
	ID        string `json:"link_id"`
	Project   string `json:"project_id"`
	Relation  string `json:"relation"`
	From      string `json:"from_object_id"`
	To        string `json:"to_object_id"`
	Basis     string `json:"basis"`
	Status    string `json:"status"`
	Rule      string `json:"rule_version"`
	Scope     string `json:"scope_json"`
	Witnesses string `json:"witness_refs"`
	Record    string `json:"assertion_record_id"`
}
func Related(ctx context.Context, db *sql.DB, owner, project string, seeds []string, limit int) ([]Link, error)

Related returns only owner/project-scoped actionable direct relationships. The caller still validates versions and budgets; a graph edge is not proof.

type LinkScope

type LinkScope struct {
	Key          string           `json:"key,omitempty"`
	Scope        Scope            `json:"scope"`
	FromSpan     *Span            `json:"from_span,omitempty"`
	ToSpan       *Span            `json:"to_span,omitempty"`
	WitnessSpans map[string]*Span `json:"witness_spans,omitempty"`
}

type Object

type Object struct {
	ID           string `json:"object_id"`
	Project      string `json:"project_id"`
	Kind         string `json:"kind"`
	Ref          string `json:"ref_id"`
	Revision     string `json:"revision_sha"`
	BodySHA      string `json:"body_sha"`
	SourceKind   string `json:"source_kind"`
	SourceID     string `json:"source_id"`
	Field        string `json:"field_path"`
	Availability string `json:"availability"`
	Session      string `json:"session_id"`
	Device       string `json:"device_id"`
	Role         string `json:"role"`
	Turn         string `json:"turn_key"`
	Prompt       string `json:"prompt_key"`
	Message      string `json:"native_message_id"`
	Parent       string `json:"parent_message_id"`
	Batch        string `json:"batch_key"`
	Ordinal      *int   `json:"source_ordinal,omitempty"`
	Count        *int   `json:"source_count,omitempty"`
	At           string `json:"occurred_at"`
	Current      bool   `json:"is_current"`
}

func GetObject

func GetObject(ctx context.Context, db *sql.DB, owner, project, id string) (Object, error)

type Policy

type Policy struct {
	Mode       string `toml:"mode" json:"mode"`
	MaxRelated int    `toml:"max_related_nodes" json:"max_related_nodes"`
}

func FromContext

func FromContext(ctx context.Context) Policy

func (Policy) Enabled

func (p Policy) Enabled() bool

func (Policy) Limit

func (p Policy) Limit() int

func (Policy) Validate

func (p Policy) Validate() error

type Scope

type Scope struct {
	Entity      string            `json:"entity"`
	Attribute   string            `json:"attribute"`
	Environment string            `json:"environment"`
	Qualifiers  map[string]string `json:"qualifiers,omitempty"`
}

type Seed

type Seed struct {
	Kind string
	Ref  string
}

type SourceRef

type SourceRef struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
}

type Span

type Span struct {
	Start int    `json:"start"`
	End   int    `json:"end"`
	SHA   string `json:"sha256"`
}

Span offsets refer to canonical UTF-8 bytes in the retained, redacted source. Hash covers the selected bytes; Endpoint.Revision pins the whole version.

func (Span) String

func (s Span) String() string

Jump to

Keyboard shortcuts

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