Documentation
¶
Overview ¶
Package model defines the core data structures for the knowledge graph.
Index ¶
- Constants
- func CommonAncestor(a, b Scope) string
- func ComputeContentHash(content string) string
- func IsValidScopeSegment(s string) bool
- func ParseScopePath(path string) ([]string, error)
- type Duration
- type Edge
- type EdgeType
- type Entry
- func (e Entry) HasConflicts() bool
- func (e Entry) HasEmbedding() bool
- func (e Entry) IsExpired() bool
- func (e Entry) ScopeObj() Scope
- func (e *Entry) SetTTL(ttl time.Duration)
- func (e *Entry) Touch()
- func (e Entry) Validate() error
- func (e Entry) WithEmbedding(embedding []float32, model string) Entry
- func (e Entry) WithFreshness(f Freshness) Entry
- func (e Entry) WithLabels(labels []string) Entry
- func (e Entry) WithMeta(m Metadata) Entry
- func (e Entry) WithProvenance(p Provenance) Entry
- func (e Entry) WithScope(scope string) Entry
- func (e Entry) WithTitle(title string) Entry
- type EventType
- type Freshness
- type ID
- type Metadata
- type Provenance
- type ProvenanceLevel
- type ResolutionStatus
- type Scope
- func (s Scope) Child(segment string) (Scope, error)
- func (s Scope) Depth() int
- func (s Scope) IsAncestorOf(other Scope) bool
- func (s Scope) IsDescendantOf(other Scope) bool
- func (s Scope) IsParentOf(other Scope) bool
- func (s Scope) Parent() string
- func (s Scope) Segments() []string
- func (s Scope) Validate() error
- func (s Scope) WithMeta(m Metadata) Scope
- type Session
- type SessionEvent
- type Source
- type SourceType
Constants ¶
const MaxContentLength = 4096
MaxContentLength is the maximum allowed length (in bytes) for entry content. Entries exceeding this limit should be broken into smaller pieces.
const MaxTitleLength = 200
MaxTitleLength is the maximum allowed length (in bytes) for entry titles.
const RootScope = "root"
RootScope is the default top-level scope.
Variables ¶
This section is empty.
Functions ¶
func CommonAncestor ¶
CommonAncestor returns the longest common prefix path between two scopes.
func ComputeContentHash ¶
ComputeContentHash returns the SHA-256 hex digest of the given content string.
func IsValidScopeSegment ¶
IsValidScopeSegment reports whether s is a valid single scope segment (alphanumeric with optional hyphens/underscores, starting with a letter).
func ParseScopePath ¶
ParseScopePath splits a scope path into its segments.
Types ¶
type Duration ¶
Duration wraps time.Duration for JSON serialization.
func (Duration) MarshalJSON ¶
MarshalJSON implements json.Marshaler for Duration.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Duration.
type Edge ¶
type Edge struct {
ID ID `json:"id"`
FromID ID `json:"from_id"`
ToID ID `json:"to_id"`
Type EdgeType `json:"type"`
Weight *float64 `json:"weight,omitempty"` // optional relationship strength
Meta Metadata `json:"meta,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
Edge represents a directed relationship between two entries.
func (Edge) EffectiveWeight ¶
EffectiveWeight returns the edge's weight, defaulting to 1.0 if unset.
func (Edge) Reverse ¶
Reverse returns a new edge with from and to swapped. Useful for bidirectional relationship queries.
func (Edge) WithWeight ¶
WithWeight returns a copy of the edge with the specified weight.
type EdgeType ¶
type EdgeType string
EdgeType defines the kind of relationship between entries.
const ( EdgeDependsOn EdgeType = "depends-on" // X requires Y EdgeContradicts EdgeType = "contradicts" // X conflicts with Y EdgeSupersedes EdgeType = "supersedes" // X replaces Y (newer version) EdgeElaborates EdgeType = "elaborates" // X provides detail about Y EdgeRelatedTo EdgeType = "related-to" // generic association )
Predefined edge types for common relationships.
func PredefinedEdgeTypes ¶
func PredefinedEdgeTypes() []EdgeType
PredefinedEdgeTypes returns all built-in edge types.
func (EdgeType) IsPredefined ¶
IsPredefined returns true if this is a built-in edge type.
type Entry ¶
type Entry struct {
ID ID `json:"id"`
Title string `json:"title,omitempty"`
Content string `json:"content"`
ContentHash string `json:"content_hash,omitempty"` // SHA-256 hex digest of content
Embedding []float32 `json:"embedding,omitempty"`
EmbeddingDim int `json:"embedding_dim,omitempty"` // dimension for mixed model support
EmbeddingModel string `json:"embedding_model,omitempty"` // which model generated this
Source Source `json:"source"`
Provenance Provenance `json:"provenance"`
Freshness Freshness `json:"freshness"`
Scope string `json:"scope"` // hierarchical scope path
TTL *Duration `json:"ttl,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Meta Metadata `json:"meta,omitempty"`
Labels []string `json:"labels,omitempty"`
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Conflict tracking - populated by queries, not stored directly
ConflictsWith []ID `json:"-"`
ResolutionStatus ResolutionStatus `json:"-"`
}
Entry represents a single piece of knowledge in the graph.
func (Entry) HasConflicts ¶
HasConflicts returns true if conflicts have been detected.
func (Entry) HasEmbedding ¶
HasEmbedding returns true if the entry has an embedding vector.
func (*Entry) Touch ¶
func (e *Entry) Touch()
Touch updates the UpdatedAt timestamp to now and recomputes the content hash.
func (Entry) WithEmbedding ¶
WithEmbedding returns a copy of the entry with the embedding set.
func (Entry) WithFreshness ¶
WithFreshness returns a copy of the entry with the freshness set.
func (Entry) WithLabels ¶
WithLabels returns a copy of the entry with the labels set.
func (Entry) WithProvenance ¶
func (e Entry) WithProvenance(p Provenance) Entry
WithProvenance returns a copy of the entry with the provenance set.
type Freshness ¶
type Freshness struct {
ObservedAt time.Time `json:"observed_at"`
ObservedBy string `json:"observed_by,omitempty"`
SourceHash string `json:"source_hash,omitempty"`
}
Freshness tracks when knowledge was last observed and whether the source has changed.
func (Freshness) FreshnessLabel ¶
FreshnessLabel returns a display label based on age since last observation: "fresh" (< 7d), "aging Nd" (7-30d), "stale Nd" (> 30d).
type ID ¶
ID is a ULID-based identifier for all entities. ULIDs are sortable, URL-safe, and encode creation time.
func MustParseID ¶
MustParseID parses a string into an ID, panicking on error.
func (ID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Metadata ¶
Metadata provides extensible key-value storage for custom attributes.
type Provenance ¶
type Provenance struct {
Level ProvenanceLevel `json:"level"`
}
Provenance tracks how a piece of knowledge was obtained.
type ProvenanceLevel ¶
type ProvenanceLevel string
ProvenanceLevel indicates how knowledge was obtained (assertion strength). These are stable values, not LLM-generated scores.
const ( ProvenanceVerified ProvenanceLevel = "verified" // user/human stated or confirmed this fact ProvenanceInferred ProvenanceLevel = "inferred" // agent derived from analysis of source material ProvenanceUncertain ProvenanceLevel = "uncertain" // source or conclusion is questionable )
type ResolutionStatus ¶
type ResolutionStatus string
ResolutionStatus indicates the state of conflict resolution.
const ( ResolutionUnresolved ResolutionStatus = "unresolved" ResolutionResolved ResolutionStatus = "resolved" ResolutionSuperseded ResolutionStatus = "superseded" )
type Scope ¶
type Scope struct {
Path string `json:"path"`
Meta Metadata `json:"meta,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
Scope represents a hierarchical namespace for organizing knowledge. Paths are dot-separated, e.g., "project.auth.oauth".
func (Scope) IsAncestorOf ¶
IsAncestorOf returns true if this scope is an ancestor of the other.
func (Scope) IsDescendantOf ¶
IsDescendantOf returns true if this scope is a descendant of the other.
func (Scope) IsParentOf ¶
IsParentOf returns true if this scope is a direct parent of the other.
type Session ¶
type Session struct {
ID ID `json:"id"`
StartedAt time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at,omitempty"`
Scope string `json:"scope,omitempty"`
Agent string `json:"agent,omitempty"`
}
Session represents an agent interaction session.
type SessionEvent ¶
type SessionEvent struct {
ID ID `json:"id"`
SessionID ID `json:"session_id"`
EventType EventType `json:"event_type"`
EntryIDs []ID `json:"entry_ids,omitempty"`
EdgeIDs []ID `json:"edge_ids,omitempty"`
Query string `json:"query,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
SessionEvent records a single CLI action within a session.
type Source ¶
type Source struct {
Type SourceType `json:"type"`
Reference string `json:"reference"` // path, URL, or identifier
Meta Metadata `json:"meta,omitempty"`
}
Source tracks the provenance of a piece of knowledge.
type SourceType ¶
type SourceType string
SourceType identifies the origin category of knowledge.
const ( SourceFile SourceType = "file" SourceURL SourceType = "url" SourceConversation SourceType = "conversation" SourceManual SourceType = "manual" )