Documentation
¶
Overview ¶
Package memory provides persistent memory storage for agent and analyst sessions.
Index ¶
- Constants
- func NormalizeCategory(c string) string
- func NormalizeConfidence(c string) string
- func NormalizeDimension(d string) string
- func NormalizeSource(s string) string
- func ParseURNToTable(urn string) (semantic.TableIdentifier, error)
- func ValidateCategory(c string) error
- func ValidateConfidence(c string) error
- func ValidateContent(text string) error
- func ValidateDimension(d string) error
- func ValidateEntityURNs(urns []string) error
- func ValidateRelatedColumns(cols []RelatedColumn) error
- func ValidateSource(s string) error
- func ValidateStatus(s string) error
- type Filter
- type MiddlewareAdapter
- type Record
- type RecordUpdate
- type RelatedColumn
- type ScoredRecord
- type Snippet
- type StalenessConfig
- type StalenessWatcher
- type Store
- type VectorQuery
Constants ¶
const ( DimensionKnowledge = "knowledge" DimensionEvent = "event" DimensionEntity = "entity" DimensionRelationship = "relationship" DimensionPreference = "preference" )
LOCOMO dimension values.
const ( StatusActive = "active" StatusStale = "stale" StatusSuperseded = "superseded" StatusArchived = "archived" )
Status values for memory records.
const ( CategoryCorrection = "correction" CategoryBusinessCtx = "business_context" CategoryDataQuality = "data_quality" CategoryUsageGuidance = "usage_guidance" CategoryRelationship = "relationship" CategoryEnhancement = "enhancement" CategoryGeneral = "general" )
Category values for memory records.
const ( SourceUser = "user" SourceAgentDiscovery = "agent_discovery" SourceEnrichmentGap = "enrichment_gap" SourceAutomation = "automation" SourceLineageEvent = "lineage_event" )
Source values for memory records.
const ( ConfidenceHigh = "high" ConfidenceMedium = "medium" ConfidenceLow = "low" )
Confidence values for memory records.
const ( MinContentLen = 10 MaxContentLen = 4000 MaxEntityURNs = 10 MaxRelatedCols = 20 DefaultLimit = 20 MaxLimit = 100 DefaultDimension = DimensionKnowledge )
Validation constraints.
Variables ¶
This section is empty.
Functions ¶
func NormalizeCategory ¶
NormalizeCategory returns the category value, defaulting to "business_context".
func NormalizeConfidence ¶
NormalizeConfidence returns the confidence value, defaulting to "medium".
func NormalizeDimension ¶
NormalizeDimension returns the dimension value, defaulting to "knowledge".
func NormalizeSource ¶
NormalizeSource returns the source value, defaulting to "user".
func ParseURNToTable ¶
func ParseURNToTable(urn string) (semantic.TableIdentifier, error)
ParseURNToTable attempts to extract a TableIdentifier from a DataHub dataset URN. URN format: urn:li:dataset:(urn:li:dataPlatform:platform,catalog.schema.table,ENV).
func ValidateCategory ¶
ValidateCategory checks whether a category value is valid.
func ValidateConfidence ¶
ValidateConfidence checks whether a confidence value is valid.
func ValidateContent ¶
ValidateContent checks content length constraints. Length is measured in bytes (matching Go's len() behavior).
func ValidateDimension ¶
ValidateDimension checks whether a dimension value is valid.
func ValidateEntityURNs ¶
ValidateEntityURNs checks the entity URN slice length.
func ValidateRelatedColumns ¶
func ValidateRelatedColumns(cols []RelatedColumn) error
ValidateRelatedColumns checks the related columns slice length.
func ValidateSource ¶
ValidateSource checks whether a source value is valid.
func ValidateStatus ¶
ValidateStatus checks whether a status value is valid.
Types ¶
type Filter ¶
type Filter struct {
CreatedBy string
Persona string
Dimension string
Category string
Status string
Source string
EntityURN string
Since *time.Time
Until *time.Time
Limit int
Offset int
// OrderBy overrides the default ordering ("created_at DESC").
// Must be a valid SQL ORDER BY clause (e.g. "last_verified ASC NULLS FIRST").
OrderBy string
}
Filter defines criteria for listing memory records.
func (*Filter) EffectiveLimit ¶
EffectiveLimit returns the limit capped to MaxLimit, defaulting to DefaultLimit.
type MiddlewareAdapter ¶
type MiddlewareAdapter struct {
// contains filtered or unexported fields
}
MiddlewareAdapter implements memory recall for the cross-injection middleware.
func NewMiddlewareAdapter ¶
func NewMiddlewareAdapter(store Store) *MiddlewareAdapter
NewMiddlewareAdapter creates a new adapter wrapping a memory store.
func (*MiddlewareAdapter) RecallForEntities ¶
func (a *MiddlewareAdapter) RecallForEntities(ctx context.Context, urns []string, persona string, limit int) ([]Snippet, error)
RecallForEntities returns memory snippets linked to the given DataHub URNs.
type Record ¶
type Record struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy string `json:"created_by"`
Persona string `json:"persona"`
Dimension string `json:"dimension"`
Content string `json:"content"`
Category string `json:"category"`
Confidence string `json:"confidence"`
Source string `json:"source"`
EntityURNs []string `json:"entity_urns"`
RelatedColumns []RelatedColumn `json:"related_columns"`
Embedding []float32 `json:"embedding,omitempty"`
Metadata map[string]any `json:"metadata"`
Status string `json:"status"`
StaleReason string `json:"stale_reason,omitempty"`
StaleAt *time.Time `json:"stale_at,omitempty"`
LastVerified *time.Time `json:"last_verified,omitempty"`
}
Record represents a single memory record.
type RecordUpdate ¶
type RecordUpdate struct {
Content string
Category string
Confidence string
Dimension string
Metadata map[string]any
Embedding []float32
}
RecordUpdate holds fields that can be updated on a memory record.
type RelatedColumn ¶
type RelatedColumn struct {
URN string `json:"urn"`
Column string `json:"column"`
Relevance string `json:"relevance"`
}
RelatedColumn represents a column related to a memory record.
type ScoredRecord ¶
ScoredRecord pairs a memory record with a similarity score.
type Snippet ¶
type Snippet struct {
ID string `json:"id"`
Content string `json:"content"`
Dimension string `json:"dimension"`
Category string `json:"category"`
Confidence string `json:"confidence"`
CreatedAt time.Time `json:"created_at"`
}
Snippet is a lightweight memory representation for cross-injection.
type StalenessConfig ¶
StalenessConfig configures the staleness watcher.
type StalenessWatcher ¶
type StalenessWatcher struct {
// contains filtered or unexported fields
}
StalenessWatcher periodically checks active memories against DataHub entity state and flags stale records.
func NewStalenessWatcher ¶
func NewStalenessWatcher(store Store, sp semantic.Provider, cfg StalenessConfig) *StalenessWatcher
NewStalenessWatcher creates a new watcher.
func (*StalenessWatcher) Start ¶
func (w *StalenessWatcher) Start(_ context.Context)
Start begins the periodic staleness check loop. It is safe to call multiple times; only the first call starts the loop.
func (*StalenessWatcher) Stop ¶
func (w *StalenessWatcher) Stop()
Stop signals the watcher to stop and waits for completion. It is safe to call multiple times.
type Store ¶
type Store interface {
// Insert creates a new memory record.
Insert(ctx context.Context, record Record) error
// Get retrieves a single memory record by ID.
Get(ctx context.Context, id string) (*Record, error)
// Update modifies fields on an existing memory record.
Update(ctx context.Context, id string, updates RecordUpdate) error
// Delete soft-deletes a memory record by setting status to archived.
Delete(ctx context.Context, id string) error
// List returns memory records matching the filter with pagination.
List(ctx context.Context, filter Filter) ([]Record, int, error)
// VectorSearch performs cosine similarity search over embeddings.
VectorSearch(ctx context.Context, query VectorQuery) ([]ScoredRecord, error)
// EntityLookup returns active memories linked to a DataHub URN.
EntityLookup(ctx context.Context, urn string, persona string) ([]Record, error)
// MarkStale flags memory records as stale with a reason.
MarkStale(ctx context.Context, ids []string, reason string) error
// MarkVerified updates the last_verified timestamp for records.
MarkVerified(ctx context.Context, ids []string) error
// Supersede marks an old record as superseded by a new one.
Supersede(ctx context.Context, oldID, newID string) error
}
Store persists and queries memory records.
func NewNoopStore ¶
func NewNoopStore() Store
NewNoopStore creates a no-op Store for use when no database is available.
func NewPostgresStore ¶
NewPostgresStore creates a new PostgreSQL memory store.