Documentation
¶
Overview ¶
Package semantic observes possible completed-answer reuse. Shadow decisions are advisory: they never serve text, change claims, or authorize generation.
Index ¶
- Constants
- func CheckProtectedTerms(original, current string) []string
- func Cosine(a, b []float32) (float64, error)
- func EntryID(e Entry) string
- func ValidatePut(p PutRequest) error
- func ValidateQuery(q Query) error
- type Candidate
- type Config
- type Embedder
- type Embedding
- type Entry
- type Index
- type Observation
- type OllamaEmbedder
- type PutRequest
- type Query
- type ReuseConfig
- type SearchResult
- type Source
- type ValidityRequest
- type ValidityResult
- type Verifier
Constants ¶
const ( DefaultVerifierMaxInputTokens int64 = 8192 DefaultVerifierMaxOutputTokens int64 = 128 DefaultVerifierTimeoutMS = 30000 MaxVerifierInputTokens int64 = 32768 MaxVerifierOutputTokens int64 = 512 MaxVerifierTimeoutMS = 120000 MaxWaitForCandidateMS = 30000 MaxVerdictBytes = 4096 // ProtectedTermsVersion identifies the lexical guard, independently of a // verifier prompt or any observed quality result. ProtectedTermsVersion = 2 )
const ( DefaultMinSimilarity = 0.9 DefaultTopK = 3 DefaultMaxScan = 1000 DefaultMaxEntries = 1000 DefaultMaxInputBytes = 8192 DefaultTimeoutMS = 10000 MaxTopK = 10 MaxScan = 10000 MaxEntries = 10000 MaxInputBytes = 32768 MaxTimeoutMS = 60000 MaxDimensions = 4096 )
Variables ¶
This section is empty.
Functions ¶
func CheckProtectedTerms ¶ added in v0.15.0
CheckProtectedTerms rejects differences in explicit quantities, code-like identifiers, URLs, quoted text, negation, symbolic operators and quantity units. Ordinary sentence capitalization and natural-language constraint words are not symbolic identifiers/operators. Proper-name hints are compared when both questions supply them; an omitted name must be resolved by the mandatory verifier against the task's bindings and evidence. Empty is not proof of equivalent intent or a correct answer. Unsupported, malformed or oversized text fails closed before extraction. Conservative false rejections remain.
func Cosine ¶
Cosine compares finite, nonzero vectors with matching bounded dimensions. float64 accumulation avoids overflowing when finite float32 values are large.
func EntryID ¶
EntryID binds an entry to its exact source snapshot within one embedding partition. Vectors and expiry do not create duplicate copies of that snapshot.
func ValidatePut ¶
func ValidatePut(p PutRequest) error
ValidatePut verifies identities, bounded vectors and the short-lived source pointer. The source artifact itself must also be checked by the index owner.
func ValidateQuery ¶
ValidateQuery checks the fully specified wire request; defaults belong to NormalizeConfig and are deliberately not inferred at the broker boundary.
Types ¶
type Config ¶
type Config struct {
Mode string `json:"mode"`
Family string `json:"family"`
Domain string `json:"domain"`
EvidenceRevision string `json:"evidence_revision"`
Bindings map[string]string `json:"bindings,omitempty"`
EmbeddingModel string `json:"embedding_model"`
MinSimilarity float64 `json:"min_similarity,omitempty"`
TopK int `json:"top_k,omitempty"`
MaxScan int `json:"max_scan,omitempty"`
MaxEntries int `json:"max_entries,omitempty"`
MaxInputBytes int `json:"max_input_bytes,omitempty"`
TimeoutMS int `json:"timeout_ms,omitempty"`
}
Config is opt-in. Mode accepts only "shadow" in this release.
func NormalizeConfig ¶
NormalizeConfig fills bounded defaults and rejects modes that could serve an answer. The returned bindings are a copy so later caller edits cannot alter it.
type Index ¶
type Index interface {
QuerySemantic(context.Context, Query) (SearchResult, error)
PutSemantic(context.Context, PutRequest) error
}
type Observation ¶
type Observation struct {
Mode string `json:"mode"`
Status string `json:"status"`
Partition string `json:"partition,omitempty"`
EmbeddingModelID string `json:"embedding_model_id,omitempty"`
EmbeddingInputTokens *int64 `json:"embedding_input_tokens"`
EmbeddingMS float64 `json:"embedding_ms,omitempty"`
TotalMS float64 `json:"total_ms"`
Search *SearchResult `json:"search,omitempty"`
Indexed bool `json:"indexed"`
GenerationAvoided bool `json:"generation_avoided"`
}
Observation deliberately has no reused/avoided tokens or alternative answer.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
// contains filtered or unexported fields
}
OllamaEmbedder captures already-installed local weights and the Ollama runtime version. It never pulls models, follows redirects, or uses environment proxies. Its methods are safe for concurrent use; its pinned identity is immutable.
func NewOllamaEmbedder ¶
func NewOllamaEmbedder(baseURL, model string, maxInputBytes int) (*OllamaEmbedder, error)
NewOllamaEmbedder validates the installed model without generating a vector. The empty origin selects http://127.0.0.1:11434. Discovery is capped at 10s.
func NewOllamaEmbedderContext ¶
func NewOllamaEmbedderContext(ctx context.Context, baseURL, model string, maxInputBytes int) (*OllamaEmbedder, error)
NewOllamaEmbedderContext also includes metadata discovery in caller's deadline.
func (*OllamaEmbedder) Close ¶
func (p *OllamaEmbedder) Close()
Close releases idle local connections. It does not unload model weights.
type PutRequest ¶
type ReuseConfig ¶ added in v0.15.0
type ReuseConfig struct {
Config
ReadOnly bool `json:"read_only"`
Intent string `json:"intent"`
VerifierModel string `json:"verifier_model"`
VerifierMaxInputTokens int64 `json:"verifier_max_input_tokens,omitempty"`
VerifierMaxOutputTokens int64 `json:"verifier_max_output_tokens,omitempty"`
VerifierTimeoutMS int `json:"verifier_timeout_ms,omitempty"`
WaitForCandidateMS int `json:"wait_for_candidate_ms,omitempty"`
}
ReuseConfig opts a read-only task into bounded candidate validation. Config's retrieval score is not an answer-validity threshold. The embedded fields have the same flat JSON names as shadow configuration.
func NormalizeReuseConfig ¶ added in v0.15.0
func NormalizeReuseConfig(c ReuseConfig) (ReuseConfig, error)
NormalizeReuseConfig preserves the shadow configuration contract while requiring an explicit controlled, read-only policy and a bounded local model. It does not discover a runtime, download weights, or call a model.
type SearchResult ¶
type ValidityRequest ¶ added in v0.15.0
type ValidityRequest struct {
OriginalQuestion string `json:"original_question"`
Question string `json:"question"`
Instructions string `json:"instructions"`
Context string `json:"context"`
CachedAnswer string `json:"cached_answer"`
Bindings map[string]string `json:"bindings"`
Intent string `json:"intent"`
}
ValidityRequest supplies both questions and the evidence against which the unchanged cached answer must be assessed. Treat its strings as task data.
type ValidityResult ¶ added in v0.15.0
type ValidityResult struct {
GenerationCalled bool `json:"generation_called"`
Complete bool `json:"complete"`
Durable bool `json:"durable"`
Verdict string `json:"verdict"`
SameIntent bool `json:"same_intent"`
SameFacts bool `json:"same_facts"`
SameConstraints bool `json:"same_constraints"`
AnswerSupported bool `json:"answer_supported"`
InputTokens *int64 `json:"input_tokens"`
OutputTokens *int64 `json:"output_tokens"`
Reused bool `json:"reused"`
// SharedWork identifies a zero-incremental-usage decision whose model work
// is accounted once by its batch's separate work record and shared receipt.
DurationMS float64 `json:"duration_ms"`
ReceiptKey string `json:"receipt_key,omitempty"`
OutputSHA256 string `json:"output_sha256,omitempty"`
}
ValidityResult separates the verdict from execution evidence supplied by the trusted adapter. Missing usage is unknown; it is never inferred as zero.
func ParseVerdict ¶ added in v0.15.0
func ParseVerdict(data []byte) (ValidityResult, error)
ParseVerdict accepts exactly the five model-authored decision fields. Usage, receipts and timing must come from the adapter, never model-authored JSON. Reading only primitive tokens also rejects nested/deep values without walking arbitrary structures. No partial result is returned on malformed input.
func (ValidityResult) Accepted ¶ added in v0.15.0
func (v ValidityResult) Accepted() bool
Accepted is a verdict check only. Callers must separately establish complete execution, known bounded usage, provenance, freshness and deterministic checks.
type Verifier ¶ added in v0.15.0
type Verifier interface {
Verify(context.Context, ValidityRequest) (ValidityResult, error)
Identity() string
}