Documentation
¶
Index ¶
- Variables
- func ProcessKalmanMutation(propertyKey string, rawMeasurement float64, kalmanCfg *KalmanConfig, ...) float64
- type AccessAccumulator
- func (a *AccessAccumulator) BufferFullness() float64
- func (a *AccessAccumulator) ClearEntity(entityID string)
- func (a *AccessAccumulator) DrainAll() map[string]*entityDelta
- func (a *AccessAccumulator) IncrementAccess(entityID string)
- func (a *AccessAccumulator) IncrementCustom(entityID string, key string, delta int64)
- func (a *AccessAccumulator) IncrementTraversal(entityID string)
- func (a *AccessAccumulator) ReadThrough(entityID string, key string, persisted int64) int64
- func (a *AccessAccumulator) SetOnBufferFull(fn func())
- func (a *AccessAccumulator) SetTimestamp(entityID string, key string, ts int64)
- type AccessFlusher
- func (f *AccessFlusher) BufferFullness() float64
- func (f *AccessFlusher) Flush()
- func (f *AccessFlusher) SetMetrics(m *observability.KnowledgePolicyMetrics)
- func (f *AccessFlusher) SetPropertySuppression(scorerFn ScorerFunc, meta EntityMetaLookup, embedInvalid EmbedInvalidateFunc)
- func (f *AccessFlusher) SetSuppressionRecheck(fn SuppressionRecheckFunc)
- func (f *AccessFlusher) Start(ctx context.Context)
- func (f *AccessFlusher) Stop()
- type AccessMetaEntry
- type AccessMetaFixedFields
- type AccessMetaStore
- type BindingTable
- func (bt *BindingTable) EdgeCount() int
- func (bt *BindingTable) HasWildEdge() bool
- func (bt *BindingTable) HasWildNode() bool
- func (bt *BindingTable) LookupEdge(edgeType string) *CompiledBinding
- func (bt *BindingTable) LookupNode(labelKey string) *CompiledBinding
- func (bt *BindingTable) NodeCount() int
- func (bt *BindingTable) SetEdge(edgeType string, cb *CompiledBinding)
- func (bt *BindingTable) SetNode(labelKey string, cb *CompiledBinding)
- func (bt *BindingTable) SetWildEdge(cb *CompiledBinding)
- func (bt *BindingTable) SetWildNode(cb *CompiledBinding)
- type CompiledBinding
- type CompiledPromotionRule
- type CompiledPropertyOverride
- type DecayFunction
- type DecayProfileBinding
- type DecayProfileBundle
- type DecayProfilePropertyRule
- type EmbedInvalidateFunc
- type EntityMeta
- type EntityMetaLookup
- type KalmanConfig
- type KalmanFilterState
- type KalmanMode
- type KalmanPropertyState
- type NodeScoringInput
- type OnAccessMutation
- type PromotionPolicyDef
- type PromotionPolicyOnAccess
- type PromotionPolicyWhenClause
- type PromotionProfileDef
- type Resolver
- func (r *Resolver) ResolveEdge(edgeType string) *CompiledBinding
- func (r *Resolver) ResolveEdgeProperty(edgeType string, propertyPath string) *CompiledBinding
- func (r *Resolver) ResolveNode(labels []string) *CompiledBinding
- func (r *Resolver) ResolveProperty(labels []string, propertyPath string) *CompiledBinding
- type ScopeType
- type ScoreFromMode
- type Scorer
- func (s *Scorer) ScoreEdge(targetID string, edgeType string, accessMeta *AccessMetaEntry, ...) ScoringResolution
- func (s *Scorer) ScoreEdgeProperty(targetID string, edgeType string, propertyPath string, ...) ScoringResolution
- func (s *Scorer) ScoreEdgeWithProperties(targetID string, edgeType string, entityProps map[string]interface{}, ...) ScoringResolution
- func (s *Scorer) ScoreNode(targetID string, labels []string, accessMeta *AccessMetaEntry, ...) ScoringResolution
- func (s *Scorer) ScoreNodeWithProperties(targetID string, labels []string, entityProps map[string]interface{}, ...) ScoringResolution
- func (s *Scorer) ScoreProperty(targetID string, labels []string, propertyPath string, ...) ScoringResolution
- func (s *Scorer) SetMetrics(m *observability.KnowledgePolicyMetrics, database string)
- type ScorerFunc
- type ScoringResolution
- type SuppressionRecheckFunc
- type VarianceTrackerState
Constants ¶
This section is empty.
Variables ¶
var NeutralResolution = ScoringResolution{FinalScore: 1.0, NoDecay: true}
NeutralResolution is returned when decay is disabled or no profile matches.
var ValidDecayFunctions = map[DecayFunction]bool{ DecayFunctionExponential: true, DecayFunctionLinear: true, DecayFunctionStep: true, DecayFunctionNone: true, }
ValidDecayFunctions is the set of valid decay function identifiers.
var ValidScopeTypes = map[ScopeType]bool{ ScopeNode: true, ScopeEdge: true, ScopeProperty: true, }
ValidScopeTypes is the set of valid scope type identifiers.
var ValidScoreFromModes = map[ScoreFromMode]bool{ ScoreFromCreated: true, ScoreFromVersion: true, ScoreFromCustom: true, ScoreFromLastAccessed: true, }
ValidScoreFromModes is the set of valid score-from mode identifiers.
Functions ¶
func ProcessKalmanMutation ¶
func ProcessKalmanMutation( propertyKey string, rawMeasurement float64, kalmanCfg *KalmanConfig, entry *AccessMetaEntry, ) float64
ProcessKalmanMutation takes a raw measurement, loads or initializes Kalman state from the entity's AccessMetaEntry.KalmanFilters map, runs the filter, and returns the filtered value. The entry is modified in place.
Inlined from pkg/filter/kalman.go:375-409 for zero-allocation hot path.
Types ¶
type AccessAccumulator ¶
type AccessAccumulator struct {
// contains filtered or unexported fields
}
AccessAccumulator is a per-P sharded counter ring for hot-path access metadata accumulation. Goroutines write to the shard of their current P via sync.Pool affinity, eliminating cross-core contention.
func NewAccessAccumulator ¶
func NewAccessAccumulator(enabled bool, maxBufferSize int) *AccessAccumulator
NewAccessAccumulator creates an accumulator with one shard per GOMAXPROCS. maxBufferSize limits distinct entity count before triggering an auto-flush. Pass 0 for unlimited (flush only on timer).
func (*AccessAccumulator) BufferFullness ¶
func (a *AccessAccumulator) BufferFullness() float64
BufferFullness returns the current entity count as a fraction of the configured maxBufferSize (in [0, 1]). Returns 0 when the accumulator is unbounded (maxBufferSize <= 0). Intended for passive-scrape observability: sustained values near 1.0 indicate the flush interval can't keep up.
func (*AccessAccumulator) ClearEntity ¶
func (a *AccessAccumulator) ClearEntity(entityID string)
ClearEntity removes any buffered deltas for the given entity from all shards.
func (*AccessAccumulator) DrainAll ¶
func (a *AccessAccumulator) DrainAll() map[string]*entityDelta
DrainAll atomically swaps out all shard deltas and returns a merged map. Used by the flush goroutine.
func (*AccessAccumulator) IncrementAccess ¶
func (a *AccessAccumulator) IncrementAccess(entityID string)
func (*AccessAccumulator) IncrementCustom ¶
func (a *AccessAccumulator) IncrementCustom(entityID string, key string, delta int64)
func (*AccessAccumulator) IncrementTraversal ¶
func (a *AccessAccumulator) IncrementTraversal(entityID string)
func (*AccessAccumulator) ReadThrough ¶
func (a *AccessAccumulator) ReadThrough(entityID string, key string, persisted int64) int64
ReadThrough returns persisted + sum(buffered deltas) across all P-local shards. This is eventually-consistent and NOT bound by MVCC snapshot isolation.
func (*AccessAccumulator) SetOnBufferFull ¶
func (a *AccessAccumulator) SetOnBufferFull(fn func())
SetOnBufferFull sets the callback invoked (in a goroutine) when the buffer reaches maxBufferSize. The flusher wires this to trigger an immediate flush.
func (*AccessAccumulator) SetTimestamp ¶
func (a *AccessAccumulator) SetTimestamp(entityID string, key string, ts int64)
type AccessFlusher ¶
type AccessFlusher struct {
// contains filtered or unexported fields
}
AccessFlusher periodically drains the accumulator and persists deltas.
func NewAccessFlusher ¶
func NewAccessFlusher(accumulator *AccessAccumulator, store AccessMetaStore, interval time.Duration) *AccessFlusher
NewAccessFlusher creates a flusher. Default interval is 2 seconds.
func (*AccessFlusher) BufferFullness ¶
func (f *AccessFlusher) BufferFullness() float64
BufferFullness returns the current accumulator buffer occupancy as a fraction in [0, 1]. Exposed so the observability layer can install it as a GaugeFunc callback.
func (*AccessFlusher) Flush ¶
func (f *AccessFlusher) Flush()
Flush performs a single drain-and-persist cycle. Exported for testing.
func (*AccessFlusher) SetMetrics ¶
func (f *AccessFlusher) SetMetrics(m *observability.KnowledgePolicyMetrics)
SetMetrics attaches a knowledge-policy metrics handle. Nil-safe; a nil handle falls back to the package-level global (observability.GetKnowledgePolicyMetrics) at fire time so late-registered metrics still flow through.
func (*AccessFlusher) SetPropertySuppression ¶
func (f *AccessFlusher) SetPropertySuppression(scorerFn ScorerFunc, meta EntityMetaLookup, embedInvalid EmbedInvalidateFunc)
SetPropertySuppression configures the flusher for property-level decay evaluation.
func (*AccessFlusher) SetSuppressionRecheck ¶
func (f *AccessFlusher) SetSuppressionRecheck(fn SuppressionRecheckFunc)
SetSuppressionRecheck configures a callback that re-evaluates entity visibility after access metadata mutations have been persisted.
func (*AccessFlusher) Start ¶
func (f *AccessFlusher) Start(ctx context.Context)
Start begins the flush loop. It exits immediately if the accumulator is disabled.
func (*AccessFlusher) Stop ¶
func (f *AccessFlusher) Stop()
Stop stops the flush loop and performs a final flush.
type AccessMetaEntry ¶
type AccessMetaEntry struct {
TargetID string `json:"targetId" msgpack:"targetId"`
TargetScope ScopeType `json:"targetScope" msgpack:"targetScope"`
Fixed AccessMetaFixedFields `json:"fixed" msgpack:"fixed"`
Overflow map[string]interface{} `json:"overflow,omitempty" msgpack:"overflow,omitempty"`
KalmanFilters map[string]*KalmanPropertyState `json:"kalmanFilters,omitempty" msgpack:"kalmanFilters,omitempty"`
LastMutatedAt int64 `json:"lastMutatedAt" msgpack:"lastMutatedAt"`
MutationCount int64 `json:"mutationCount" msgpack:"mutationCount"`
}
AccessMetaEntry is the full persisted entry per target.
type AccessMetaFixedFields ¶
type AccessMetaFixedFields struct {
AccessCount int64 `json:"accessCount" msgpack:"accessCount"`
LastAccessedAt int64 `json:"lastAccessedAt" msgpack:"lastAccessedAt"`
TraversalCount int64 `json:"traversalCount" msgpack:"traversalCount"`
LastTraversedAt int64 `json:"lastTraversedAt" msgpack:"lastTraversedAt"`
}
AccessMetaFixedFields is the fast-path fixed-layout struct.
type AccessMetaStore ¶
type AccessMetaStore interface {
GetAccessMeta(entityID string) (*AccessMetaEntry, error)
PutAccessMeta(entityID string, entry *AccessMetaEntry) error
}
AccessMetaStore is the persistence interface for AccessMetaEntry.
type BindingTable ¶
type BindingTable struct {
// contains filtered or unexported fields
}
BindingTable is the compiled lookup for all labels and edge types.
func BuildBindingTable ¶
func BuildBindingTable( bundles map[string]*DecayProfileBundle, bindings map[string]*DecayProfileBinding, profiles map[string]*PromotionProfileDef, policies map[string]*PromotionPolicyDef, ) (*BindingTable, error)
BuildBindingTable compiles all decay bindings and promotion policies into a BindingTable ready for the resolver. Returns an error if cross-references are invalid or if two bindings conflict (same target key and Order).
func NewBindingTable ¶
func NewBindingTable() *BindingTable
NewBindingTable creates an empty BindingTable.
func (*BindingTable) EdgeCount ¶
func (bt *BindingTable) EdgeCount() int
EdgeCount returns the number of specific edge bindings.
func (*BindingTable) HasWildEdge ¶
func (bt *BindingTable) HasWildEdge() bool
HasWildEdge returns whether a wildcard edge binding is set.
func (*BindingTable) HasWildNode ¶
func (bt *BindingTable) HasWildNode() bool
HasWildNode returns whether a wildcard node binding is set.
func (*BindingTable) LookupEdge ¶
func (bt *BindingTable) LookupEdge(edgeType string) *CompiledBinding
LookupEdge returns the compiled binding for the given edge type. Returns the wildcard binding if no specific match exists, or nil if neither exists.
func (*BindingTable) LookupNode ¶
func (bt *BindingTable) LookupNode(labelKey string) *CompiledBinding
LookupNode returns the compiled binding for the given sorted label set. Returns the wildcard binding if no specific match exists, or nil if neither exists.
func (*BindingTable) NodeCount ¶
func (bt *BindingTable) NodeCount() int
NodeCount returns the number of specific node bindings.
func (*BindingTable) SetEdge ¶
func (bt *BindingTable) SetEdge(edgeType string, cb *CompiledBinding)
SetEdge sets a compiled binding for an edge type.
func (*BindingTable) SetNode ¶
func (bt *BindingTable) SetNode(labelKey string, cb *CompiledBinding)
SetNode sets a compiled binding for a label key.
func (*BindingTable) SetWildEdge ¶
func (bt *BindingTable) SetWildEdge(cb *CompiledBinding)
SetWildEdge sets the wildcard edge binding.
func (*BindingTable) SetWildNode ¶
func (bt *BindingTable) SetWildNode(cb *CompiledBinding)
SetWildNode sets the wildcard node binding.
type CompiledBinding ¶
type CompiledBinding struct {
DecayProfile *DecayProfileBundle
DecayBinding *DecayProfileBinding
PromotionPolicy *PromotionPolicyDef
VisibilityThreshold float64
ScoreFrom ScoreFromMode
ScoreFromProperty string
Function DecayFunction
HalfLifeNanos int64
ThresholdAgeNanos int64
DecayFloor float64
NoDecay bool
HasNoDecayProperty bool
CompiledPropertyRules map[string]*CompiledPropertyOverride
CompiledPromotionRules []CompiledPromotionRule
}
CompiledBinding is the pre-flattened lookup entry for a label/edge-type.
type CompiledPromotionRule ¶
type CompiledPromotionRule struct {
Predicate string
Profile *PromotionProfileDef
Order int
}
type CompiledPropertyOverride ¶
type CompiledPropertyOverride struct {
NoDecay bool
HalfLifeNanos int64
ThresholdAgeNanos int64
DecayFloor float64
Function DecayFunction
}
CompiledPropertyOverride is a pre-expanded property-level scoring override.
type DecayFunction ¶
type DecayFunction string
DecayFunction identifies a scoring function.
const ( DecayFunctionExponential DecayFunction = "exponential" DecayFunctionLinear DecayFunction = "linear" DecayFunctionStep DecayFunction = "step" DecayFunctionNone DecayFunction = "none" )
type DecayProfileBinding ¶
type DecayProfileBinding struct {
Name string `json:"name" msgpack:"name"`
TargetLabels []string `json:"targetLabels,omitempty" msgpack:"targetLabels,omitempty"`
TargetEdgeType string `json:"targetEdgeType,omitempty" msgpack:"targetEdgeType,omitempty"`
IsWildcard bool `json:"isWildcard" msgpack:"isWildcard"`
IsEdge bool `json:"isEdge" msgpack:"isEdge"`
ProfileRef string `json:"profileRef,omitempty" msgpack:"profileRef,omitempty"`
NoDecay bool `json:"noDecay,omitempty" msgpack:"noDecay,omitempty"`
HalfLifeSeconds int64 `json:"halfLifeSeconds,omitempty" msgpack:"halfLifeSeconds,omitempty"`
ScoreFloor float64 `json:"scoreFloor,omitempty" msgpack:"scoreFloor,omitempty"`
VisibilityThreshold *float64 `json:"visibilityThreshold,omitempty" msgpack:"visibilityThreshold,omitempty"`
PropertyRules []DecayProfilePropertyRule `json:"propertyRules,omitempty" msgpack:"propertyRules,omitempty"`
Order int `json:"order" msgpack:"order"`
}
DecayProfileBinding is a targeted binding (has FOR clause).
type DecayProfileBundle ¶
type DecayProfileBundle struct {
Name string `json:"name" msgpack:"name"`
HalfLifeSeconds int64 `json:"halfLifeSeconds" msgpack:"halfLifeSeconds"`
VisibilityThreshold float64 `json:"visibilityThreshold" msgpack:"visibilityThreshold"`
ScoreFloor float64 `json:"scoreFloor" msgpack:"scoreFloor"`
Function DecayFunction `json:"function" msgpack:"function"`
Scope ScopeType `json:"scope" msgpack:"scope"`
DecayEnabled bool `json:"decayEnabled" msgpack:"decayEnabled"`
ScoreFrom ScoreFromMode `json:"scoreFrom" msgpack:"scoreFrom"`
ScoreFromProperty string `json:"scoreFromProperty,omitempty" msgpack:"scoreFromProperty,omitempty"`
Enabled bool `json:"enabled" msgpack:"enabled"`
}
DecayProfileBundle is a reusable parameter bundle (no FOR clause).
HalfLifeSeconds carries the inversion signal: a negative value flips the chosen Function in place, so the compiled score becomes `1 - f(age, |halfLife|)` instead of `f(age, halfLife)`. The score then grows from 0 toward 1.0 as age increases, instead of falling toward 0. Combined with ScoreFromLastAccessed this implements an idle-time consolidation curve: time without access strengthens the score and an access resets the anchor (and thus the score) back to 0. The inversion is purely a curve property and composes with every Function family and every ScoreFrom anchor.
type DecayProfilePropertyRule ¶
type DecayProfilePropertyRule struct {
PropertyPath string `json:"propertyPath" msgpack:"propertyPath"`
NoDecay bool `json:"noDecay,omitempty" msgpack:"noDecay,omitempty"`
ProfileRef string `json:"profileRef,omitempty" msgpack:"profileRef,omitempty"`
HalfLifeSeconds int64 `json:"halfLifeSeconds,omitempty" msgpack:"halfLifeSeconds,omitempty"`
ScoreFloor float64 `json:"scoreFloor,omitempty" msgpack:"scoreFloor,omitempty"`
Order int `json:"order" msgpack:"order"`
}
DecayProfilePropertyRule is an inline property-level rule inside a binding.
type EmbedInvalidateFunc ¶
type EmbedInvalidateFunc func(entityID string)
EmbedInvalidateFunc is called when property suppression state changes.
type EntityMeta ¶
type EntityMeta struct {
Scope ScopeType
Labels []string
EdgeType string
PropertyKeys []string
CreatedAtNanos int64
VersionAtNanos int64
}
EntityMeta describes the storage metadata the flusher needs to resolve access-time policy bindings and property visibility.
type EntityMetaLookup ¶
type EntityMetaLookup interface {
GetEntityMeta(entityID string) (EntityMeta, error)
}
EntityMetaLookup provides entity metadata needed by flusher policy and property suppression evaluation.
type KalmanConfig ¶
type KalmanConfig struct {
Mode KalmanMode `json:"mode" msgpack:"mode"`
Q float64 `json:"q" msgpack:"q"`
R float64 `json:"r,omitempty" msgpack:"r,omitempty"`
VarianceScale float64 `json:"varianceScale,omitempty" msgpack:"varianceScale,omitempty"`
WindowSize int `json:"windowSize,omitempty" msgpack:"windowSize,omitempty"`
}
KalmanConfig holds the Kalman filter configuration for an ON ACCESS mutation.
type KalmanFilterState ¶
type KalmanFilterState struct {
X float64 `json:"x" msgpack:"x"`
LastX float64 `json:"lx" msgpack:"lx"`
P float64 `json:"p" msgpack:"p"`
K float64 `json:"k" msgpack:"k"`
E float64 `json:"e" msgpack:"e"`
Q float64 `json:"q" msgpack:"q"`
R float64 `json:"r" msgpack:"r"`
VarianceScale float64 `json:"vs" msgpack:"vs"`
Observations int `json:"n" msgpack:"n"`
}
KalmanFilterState is the per-property Kalman filter state.
type KalmanMode ¶
type KalmanMode string
KalmanMode identifies how the Kalman filter is configured for a mutation.
const ( KalmanModeNone KalmanMode = "" KalmanModeAuto KalmanMode = "auto" KalmanModeManual KalmanMode = "manual" )
type KalmanPropertyState ¶
type KalmanPropertyState struct {
FilteredValue float64 `json:"filteredValue" msgpack:"filteredValue"`
Filter KalmanFilterState `json:"filter" msgpack:"filter"`
Variance *VarianceTrackerState `json:"variance,omitempty" msgpack:"variance,omitempty"`
}
KalmanPropertyState holds the Kalman filter state and variance tracker state for a single property that uses WITH KALMAN.
type NodeScoringInput ¶
type NodeScoringInput struct {
EntityID string
Labels []string
CreatedAtNanos int64
VersionAtNanos int64
}
NodeScoringInput carries the primitive fields from a storage.Node needed for scoring without importing pkg/storage (avoiding an import cycle).
type OnAccessMutation ¶
type OnAccessMutation struct {
Expression string `json:"expression" msgpack:"expression"`
Kalman *KalmanConfig `json:"kalman,omitempty" msgpack:"kalman,omitempty"`
}
OnAccessMutation is a single SET expression inside an ON ACCESS block.
type PromotionPolicyDef ¶
type PromotionPolicyDef struct {
Name string `json:"name" msgpack:"name"`
TargetLabels []string `json:"targetLabels,omitempty" msgpack:"targetLabels,omitempty"`
TargetEdgeType string `json:"targetEdgeType,omitempty" msgpack:"targetEdgeType,omitempty"`
IsWildcard bool `json:"isWildcard" msgpack:"isWildcard"`
IsEdge bool `json:"isEdge" msgpack:"isEdge"`
OnAccess *PromotionPolicyOnAccess `json:"onAccess,omitempty" msgpack:"onAccess,omitempty"`
WhenClauses []PromotionPolicyWhenClause `json:"whenClauses,omitempty" msgpack:"whenClauses,omitempty"`
Enabled bool `json:"enabled" msgpack:"enabled"`
}
PromotionPolicyDef is a targeted promotion policy.
type PromotionPolicyOnAccess ¶
type PromotionPolicyOnAccess struct {
Mutations []OnAccessMutation `json:"mutations" msgpack:"mutations"`
}
PromotionPolicyOnAccess is the ON ACCESS block definition.
type PromotionPolicyWhenClause ¶
type PromotionPolicyWhenClause struct {
PropertyPath string `json:"propertyPath,omitempty" msgpack:"propertyPath,omitempty"`
Predicate string `json:"predicate" msgpack:"predicate"`
ProfileRef string `json:"profileRef" msgpack:"profileRef"`
Order int `json:"order" msgpack:"order"`
}
PromotionPolicyWhenClause is a WHEN predicate inside a policy.
type PromotionProfileDef ¶
type PromotionProfileDef struct {
Name string `json:"name" msgpack:"name"`
Scope ScopeType `json:"scope" msgpack:"scope"`
Multiplier float64 `json:"multiplier" msgpack:"multiplier"`
ScoreFloor float64 `json:"scoreFloor" msgpack:"scoreFloor"`
ScoreCap float64 `json:"scoreCap" msgpack:"scoreCap"`
Enabled bool `json:"enabled" msgpack:"enabled"`
}
PromotionProfileDef is a reusable promotion parameter bundle.
Multiplier > 1.0 boosts the decayed score; Multiplier < 1.0 dampens it (e.g. 0.5 halves the score). A dampening multiplier paired with an inverted DecayProfileBundle (negative HalfLifeSeconds) implements "punish frequent access" semantics: the inverted curve makes idle entries strong, the dampening multiplier knocks down hot-path entries once a WHEN predicate trips, so frequently-accessed nodes/edges decay faster while idle ones gain strength. ScoreFloor and ScoreCap clamp the final score after the multiplier is applied.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves effective decay and promotion configuration for a target.
func NewResolver ¶
func NewResolver(bt *BindingTable, logger *log.Logger) *Resolver
NewResolver creates a Resolver backed by the given BindingTable. A nil logger disables runtime conflict warnings.
func (*Resolver) ResolveEdge ¶
func (r *Resolver) ResolveEdge(edgeType string) *CompiledBinding
ResolveEdge returns the CompiledBinding for an edge identified by its type.
func (*Resolver) ResolveEdgeProperty ¶
func (r *Resolver) ResolveEdgeProperty(edgeType string, propertyPath string) *CompiledBinding
ResolveEdgeProperty returns a CompiledBinding for a specific property on an edge. If the binding has a property-level override, a copy with the override applied is returned.
func (*Resolver) ResolveNode ¶
func (r *Resolver) ResolveNode(labels []string) *CompiledBinding
ResolveNode returns the CompiledBinding for a node identified by its labels. Labels are sorted internally; the caller's slice is not modified.
func (*Resolver) ResolveProperty ¶
func (r *Resolver) ResolveProperty(labels []string, propertyPath string) *CompiledBinding
ResolveProperty returns a CompiledBinding for a specific property on a node. If the binding has a property-level override, a copy with the override applied is returned.
type ScopeType ¶
type ScopeType string
ScopeType identifies whether a profile/policy targets nodes, edges, or properties.
type ScoreFromMode ¶
type ScoreFromMode string
ScoreFromMode identifies the score start-time anchor.
const ( ScoreFromCreated ScoreFromMode = "CREATED" ScoreFromVersion ScoreFromMode = "VERSION" ScoreFromCustom ScoreFromMode = "CUSTOM" // ScoreFromLastAccessed anchors the score at AccessMetaEntry.Fixed. // LastAccessedAt. Time-since-last-access is the "age" the decay // function consumes — pairs with DecayFunctionInverseExponential // to implement an idle-time consolidation curve where time without // access strengthens the score and access resets it. Falls back to // createdAt when no access has been recorded. ScoreFromLastAccessed ScoreFromMode = "LAST_ACCESSED" )
type Scorer ¶
type Scorer struct {
// contains filtered or unexported fields
}
Scorer computes decay and promotion scores using the shared resolver.
func NewScorer ¶
NewScorer creates a Scorer. When decayEnabled is false, all Score* methods return NeutralResolution.
func (*Scorer) ScoreEdge ¶
func (s *Scorer) ScoreEdge( targetID string, edgeType string, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) ScoreEdgeProperty ¶
func (s *Scorer) ScoreEdgeProperty( targetID string, edgeType string, propertyPath string, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) ScoreEdgeWithProperties ¶
func (s *Scorer) ScoreEdgeWithProperties( targetID string, edgeType string, entityProps map[string]interface{}, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) ScoreNode ¶
func (s *Scorer) ScoreNode( targetID string, labels []string, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) ScoreNodeWithProperties ¶
func (s *Scorer) ScoreNodeWithProperties( targetID string, labels []string, entityProps map[string]interface{}, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) ScoreProperty ¶
func (s *Scorer) ScoreProperty( targetID string, labels []string, propertyPath string, accessMeta *AccessMetaEntry, createdAt, versionAt, nowNanos int64, ) ScoringResolution
func (*Scorer) SetMetrics ¶
func (s *Scorer) SetMetrics(m *observability.KnowledgePolicyMetrics, database string)
SetMetrics attaches an observability handle to the Scorer. Safe to call after construction; passing nil falls back to the package-level global (observability.GetKnowledgePolicyMetrics) so late-initialised metrics still flow through. `database` is included on every per-tenant metric labelset when the bag was constructed with tenantLabelsEnabled=true.
type ScorerFunc ¶
ScorerFunc returns a Scorer for the given namespace. Returns nil if none.
type ScoringResolution ¶
type ScoringResolution struct {
TargetID string
TargetScope ScopeType
ResolvedDecayProfileID string
ResolvedDecayFunction DecayFunction
ResolvedScoreFrom ScoreFromMode
ResolutionSourceChain []string
AppliedDecayProfileNames []string
AppliedPromotionPolicyName string
AppliedPromotionProfileName string
EffectiveRate float64
EffectiveThreshold float64
EffectiveFloor float64
EffectiveMultiplier float64
BaseScore float64
FinalScore float64
NoDecay bool
SuppressionEligible bool
Explanation string
}
ScoringResolution is the result of resolving and scoring a target entity.
func ShouldSuppressEdge ¶
func ShouldSuppressEdge( scorer *Scorer, edgeType string, entityID string, accessMeta *AccessMetaEntry, createdAtNanos, nowNanos int64, ) (bool, ScoringResolution)
ShouldSuppressEdge determines whether an edge should be hidden from query results based on its decay score.
func ShouldSuppressNode ¶
func ShouldSuppressNode( scorer *Scorer, input NodeScoringInput, accessMeta *AccessMetaEntry, nowNanos int64, ) (bool, ScoringResolution)
ShouldSuppressNode determines whether a node should be hidden from query results based on its decay score. Returns the suppress decision and the full scoring resolution for diagnostics.
type SuppressionRecheckFunc ¶
type SuppressionRecheckFunc func(entityID string, meta EntityMeta)
SuppressionRecheckFunc re-evaluates entity visibility after access metadata changes.
type VarianceTrackerState ¶
type VarianceTrackerState struct {
Window []float64 `json:"w" msgpack:"w"`
WindowIdx int `json:"wi" msgpack:"wi"`
SumMean float64 `json:"sm" msgpack:"sm"`
SumVar float64 `json:"sv" msgpack:"sv"`
Mean float64 `json:"m" msgpack:"m"`
Variance float64 `json:"v" msgpack:"v"`
InverseN float64 `json:"in" msgpack:"in"`
}
VarianceTrackerState is the serializable state for auto-R calculation.