memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package memory implements the Memory Artifact family and deterministic retrieval behavior.

Index

Constants

View Source
const Family = "memory"

Variables

This section is empty.

Functions

func AdmitsFTSText

func AdmitsFTSText(query, text string) bool

func AnalyzeText

func AnalyzeText(value string) string

func CanonicalEmbedding

func CanonicalEmbedding(values []float64, dimension int, normalization string) ([]float64, error)

func CanonicalJSON

func CanonicalJSON(value any) ([]byte, error)

func ContentBytes

func ContentBytes(content Content) ([]byte, error)

func ContentHash

func ContentHash(content Content) (string, error)

func EmbeddingContentHash

func EmbeddingContentHash(profile EmbeddingProfile, entryContentHash string) (string, error)

func EntryContentBytes

func EntryContentBytes(kind, text string, sourceRefs []source.Ref, artifactRefs []artifact.Ref) ([]byte, error)

func EntryContentHash

func EntryContentHash(kind, text string, sourceRefs []source.Ref, artifactRefs []artifact.Ref) (string, error)

func ExtractionInstructions

func ExtractionInstructions(profile ExtractionProfile) (string, error)

func ExtractionInstructionsVersion

func ExtractionInstructionsVersion(profile ExtractionProfile) (string, error)

func FTSMatchQuery

func FTSMatchQuery(value string) (string, bool)

func NormalizeEmbedding

func NormalizeEmbedding(values []float64, dimension int) ([]float64, error)

func NormalizeKind

func NormalizeKind(value string) (string, error)

func NormalizeReason

func NormalizeReason(value *string) (*string, error)

func NormalizeText

func NormalizeText(value string) (string, error)

func ValidateContentHash

func ValidateContentHash(value string) (string, error)

func ValidateEmbedding

func ValidateEmbedding(values []float64, dimension int) ([]float64, error)

func ValidateIdentifier

func ValidateIdentifier(value string) (string, error)

Types

type ArtifactResolver

type ArtifactResolver interface {
	Get(context.Context, artifact.Snapshot) (artifact.Snapshot, error)
}

type Backend

Backend is the exact persistence/search surface consumed by Memory. Commit must atomically enforce the Artifact head CAS and replace all projections.

type BackendConfigurationError

type BackendConfigurationError struct{ Detail string }

func (*BackendConfigurationError) Error

func (e *BackendConfigurationError) Error() string

type CandidatePipeline

type CandidatePipeline interface {
	Extract(context.Context, CandidateRequest) ([]EntryInput, error)
}

type CandidateRequest

type CandidateRequest struct {
	// contains filtered or unexported fields
}

func NewCandidateRequest

func NewCandidateRequest(
	sources []source.Value,
	artifacts []artifact.Snapshot,
	currentEntries []EntryVersion,
) (CandidateRequest, error)

func (CandidateRequest) Artifacts

func (r CandidateRequest) Artifacts() []artifact.Snapshot

func (CandidateRequest) CurrentEntries

func (r CandidateRequest) CurrentEntries() []EntryVersion

func (CandidateRequest) Sources

func (r CandidateRequest) Sources() []source.Value

type CanonicalError

type CanonicalError struct {
	Code   string
	Detail any
}

CanonicalError reports a stable Memory canonicalization failure.

func (*CanonicalError) Error

func (e *CanonicalError) Error() string

type Capabilities

type Capabilities struct {
	FTS              bool
	Vector           bool
	Hybrid           bool
	EmbeddingProfile *EmbeddingProfile
}

type CapabilityNotSupportedError

type CapabilityNotSupportedError struct {
	Capability string
	Detail     string
}

func (*CapabilityNotSupportedError) Error

type Change

type Change struct {
	// contains filtered or unexported fields
}

func NewChange

func NewChange(op ChangeOp, entryID string, fromVersion, toVersion, reason *string) (Change, error)

func (Change) Clone

func (c Change) Clone() Change

func (Change) EntryID

func (c Change) EntryID() string

func (Change) FromEntryVersionID

func (c Change) FromEntryVersionID() *string

func (Change) Op

func (c Change) Op() ChangeOp

func (Change) Reason

func (c Change) Reason() *string

func (Change) ToEntryVersionID

func (c Change) ToEntryVersionID() *string

type ChangeOp

type ChangeOp string
const (
	Add        ChangeOp = "add"
	Revise     ChangeOp = "revise"
	Deactivate ChangeOp = "deactivate"
	Reactivate ChangeOp = "reactivate"
)

type ChannelHit

type ChannelHit struct {
	MemoryRef      artifact.Ref
	EntryID        string
	EntryVersionID string
	Text           string
	Distance       *float64
}

func AdmitFTSCandidates

func AdmitFTSCandidates(query string, candidates []ChannelHit) []ChannelHit

func AdmitVectorCandidates

func AdmitVectorCandidates(candidates []ChannelHit) []ChannelHit

func NewChannelHit

func NewChannelHit(memoryRef artifact.Ref, entryID, entryVersionID, text string, distance *float64) (ChannelHit, error)

func (ChannelHit) Clone

func (h ChannelHit) Clone() ChannelHit

type Citation

type Citation struct {
	MemoryRef      artifact.Ref
	EntryID        string
	EntryVersionID string
}

type Clock

type Clock func() time.Time

type Commit

type Commit struct {
	// contains filtered or unexported fields
}

Commit is the complete authoritative revision and its transaction-coupled entry/index rows.

func NewCommit

func NewCommit(
	base *Memory,
	next Memory,
	contentHash string,
	entryVersions []EntryVersion,
	projections []Projection,
) Commit

func (Commit) Base

func (c Commit) Base() *Memory

func (Commit) ContentHash

func (c Commit) ContentHash() string

func (Commit) EntryVersions

func (c Commit) EntryVersions() []EntryVersion

func (Commit) Memory

func (c Commit) Memory() Memory

func (Commit) Projections

func (c Commit) Projections() []Projection

type Content

type Content struct {
	// contains filtered or unexported fields
}

func NewContent

func NewContent(manifest Manifest, changes []Change) Content

func (Content) Changes

func (c Content) Changes() []Change

func (Content) Manifest

func (c Content) Manifest() Manifest

func (Content) Schema

func (c Content) Schema() string

type ContentEvidenceProjector

type ContentEvidenceProjector struct {
	// contains filtered or unexported fields
}

ContentEvidenceProjector exposes captured Content Source bodies while retaining the default projection for every other exact Source type.

func NewContentEvidenceProjector

func NewContentEvidenceProjector(fallback EvidenceProjector) ContentEvidenceProjector

func (ContentEvidenceProjector) ProjectArtifact

func (p ContentEvidenceProjector) ProjectArtifact(value artifact.Snapshot) (any, error)

func (ContentEvidenceProjector) ProjectSource

func (p ContentEvidenceProjector) ProjectSource(value source.Value) (any, error)

type DefaultEvidenceProjector

type DefaultEvidenceProjector struct{}

func (DefaultEvidenceProjector) ProjectArtifact

func (DefaultEvidenceProjector) ProjectArtifact(value artifact.Snapshot) (any, error)

func (DefaultEvidenceProjector) ProjectSource

func (DefaultEvidenceProjector) ProjectSource(value source.Value) (any, error)

type Draft

type Draft = artifact.Draft[Content]

func NewDraft

func NewDraft(content Content, sources []source.Ref, artifacts []artifact.Ref) (Draft, error)

type EmbeddingProfile

type EmbeddingProfile struct {
	ProfileID     string
	Model         string
	Dimension     int
	Distance      string
	Normalization string
}

func NewEmbeddingProfile

func NewEmbeddingProfile(profileID, model string, dimension int, normalization string) (EmbeddingProfile, error)

func (EmbeddingProfile) DimensionCount

func (p EmbeddingProfile) DimensionCount() int

func (EmbeddingProfile) ID

func (p EmbeddingProfile) ID() string

func (EmbeddingProfile) ModelName

func (p EmbeddingProfile) ModelName() string

func (EmbeddingProfile) NormalizationMode

func (p EmbeddingProfile) NormalizationMode() string

type EntryInactiveError

type EntryInactiveError struct{ EntryID string }

func (*EntryInactiveError) Error

func (e *EntryInactiveError) Error() string

type EntryInput

type EntryInput struct {
	// contains filtered or unexported fields
}

func NewEntryInput

func NewEntryInput(
	entry *EntryVersion,
	kind, text string,
	sources []source.Value,
	artifacts []artifact.Snapshot,
	reason *string,
) EntryInput

func (EntryInput) Artifacts

func (i EntryInput) Artifacts() []artifact.Snapshot

func (EntryInput) Entry

func (i EntryInput) Entry() *EntryVersion

func (EntryInput) Kind

func (i EntryInput) Kind() string

func (EntryInput) Reason

func (i EntryInput) Reason() *string

func (EntryInput) Sources

func (i EntryInput) Sources() []source.Value

func (EntryInput) Text

func (i EntryInput) Text() string

type EntryNotFoundError

type EntryNotFoundError struct{ EntryID string }

func (*EntryNotFoundError) Error

func (e *EntryNotFoundError) Error() string

type EntryState

type EntryState string
const (
	Active   EntryState = "active"
	Inactive EntryState = "inactive"
)

type EntryVersion

type EntryVersion struct {
	MemoryArtifactID  string
	EntryID           string
	EntryVersionID    string
	Version           int64
	PreviousVersionID *string
	Kind              string
	Text              string
	EntryContentHash  string
	CreatedInRevision int64
	Sources           []source.Ref
	Artifacts         []artifact.Ref
}

func (EntryVersion) Clone

func (e EntryVersion) Clone() EntryVersion

type EvidenceProjectionError

type EvidenceProjectionError struct{ Kind string }

func (*EvidenceProjectionError) Error

func (e *EvidenceProjectionError) Error() string

type EvidenceProjector

type EvidenceProjector interface {
	ProjectSource(source.Value) (any, error)
	ProjectArtifact(artifact.Snapshot) (any, error)
}

type ExtractionCandidate

type ExtractionCandidate struct {
	// contains filtered or unexported fields
}

func NewExtractionCandidate

func NewExtractionCandidate(
	intent ExtractionIntent,
	kind, text string,
	evidenceIDs []string,
	entryID, reason *string,
) (ExtractionCandidate, error)

func (ExtractionCandidate) EntryID

func (c ExtractionCandidate) EntryID() *string

func (ExtractionCandidate) EvidenceIDs

func (c ExtractionCandidate) EvidenceIDs() []string

func (ExtractionCandidate) Intent

func (ExtractionCandidate) Kind

func (c ExtractionCandidate) Kind() string

func (ExtractionCandidate) Reason

func (c ExtractionCandidate) Reason() *string

func (ExtractionCandidate) Text

func (c ExtractionCandidate) Text() string

type ExtractionCurrentEntry

type ExtractionCurrentEntry struct {
	// contains filtered or unexported fields
}

func (ExtractionCurrentEntry) EntryID

func (e ExtractionCurrentEntry) EntryID() string

func (ExtractionCurrentEntry) Kind

func (e ExtractionCurrentEntry) Kind() string

func (ExtractionCurrentEntry) Text

func (e ExtractionCurrentEntry) Text() string

type ExtractionEvidence

type ExtractionEvidence struct {
	// contains filtered or unexported fields
}

func (ExtractionEvidence) Content

func (e ExtractionEvidence) Content() any

func (ExtractionEvidence) EvidenceID

func (e ExtractionEvidence) EvidenceID() string

func (ExtractionEvidence) EvidenceType

func (e ExtractionEvidence) EvidenceType() artifact.EvidenceKind

type ExtractionInput

type ExtractionInput struct {
	// contains filtered or unexported fields
}

func (ExtractionInput) CurrentEntries

func (i ExtractionInput) CurrentEntries() []ExtractionCurrentEntry

func (ExtractionInput) Evidence

func (i ExtractionInput) Evidence() []ExtractionEvidence

func (ExtractionInput) MarshalJSON

func (i ExtractionInput) MarshalJSON() ([]byte, error)

type ExtractionIntent

type ExtractionIntent string
const (
	ExtractionAdd    ExtractionIntent = "add"
	ExtractionRevise ExtractionIntent = "revise"
)

type ExtractionOutput

type ExtractionOutput struct {
	// contains filtered or unexported fields
}

func NewExtractionOutput

func NewExtractionOutput(candidates []ExtractionCandidate) ExtractionOutput

func (ExtractionOutput) Candidates

func (o ExtractionOutput) Candidates() []ExtractionCandidate

type ExtractionProfile

type ExtractionProfile string
const (
	CodingProfile       ExtractionProfile = "coding"
	ConversationProfile ExtractionProfile = "conversation"
)

type Hit

type Hit struct {
	MemoryRef      artifact.Ref
	EntryID        string
	EntryVersionID string
	Text           string
	Score          float64
	MatchedBy      []MatchedBy
}

func FuseRankings

func FuseRankings(fts, vector []ChannelHit, limit int) ([]Hit, error)

func (Hit) Clone

func (h Hit) Clone() Hit

type IDFactory

type IDFactory func(string) (string, error)

type InvalidCandidateError

type InvalidCandidateError struct {
	Code   string
	Detail string
}

func (*InvalidCandidateError) Error

func (e *InvalidCandidateError) Error() string

type InvalidCitationError

type InvalidCitationError struct{ Code string }

func (*InvalidCitationError) Error

func (e *InvalidCitationError) Error() string

type InvalidEmbeddingError

type InvalidEmbeddingError struct{ Code string }

func (*InvalidEmbeddingError) Error

func (e *InvalidEmbeddingError) Error() string

type InvalidEvidenceError

type InvalidEvidenceError struct{ Code string }

func (*InvalidEvidenceError) Error

func (e *InvalidEvidenceError) Error() string

type InvalidOperationError

type InvalidOperationError struct{ Code string }

func (*InvalidOperationError) Error

func (e *InvalidOperationError) Error() string

type LLMCandidatePipeline

type LLMCandidatePipeline struct {
	// contains filtered or unexported fields
}

func (*LLMCandidatePipeline) Extract

func (p *LLMCandidatePipeline) Extract(ctx context.Context, request CandidateRequest) ([]EntryInput, error)

type LLMReranker

type LLMReranker struct {
	// contains filtered or unexported fields
}

func (*LLMReranker) PolicyID

func (*LLMReranker) PolicyID() string

func (*LLMReranker) Rerank

func (r *LLMReranker) Rerank(
	ctx context.Context,
	query string,
	candidates []Hit,
	limit int,
) (RerankDecision, error)

type Manifest

type Manifest struct {
	// contains filtered or unexported fields
}

func NewManifest

func NewManifest(entries []ManifestEntry) Manifest

func (Manifest) Entries

func (m Manifest) Entries() []ManifestEntry

func (Manifest) Format

func (m Manifest) Format() string

type ManifestEntry

type ManifestEntry struct {
	// contains filtered or unexported fields
}

func NewManifestEntry

func NewManifestEntry(entryID, entryVersionID, entryContentHash string, state EntryState) (ManifestEntry, error)

func (ManifestEntry) EntryContentHash

func (e ManifestEntry) EntryContentHash() string

func (ManifestEntry) EntryID

func (e ManifestEntry) EntryID() string

func (ManifestEntry) EntryVersionID

func (e ManifestEntry) EntryVersionID() string

func (ManifestEntry) State

func (e ManifestEntry) State() EntryState

type MatchedBy

type MatchedBy string
const (
	MatchedFTS    MatchedBy = "fts"
	MatchedVector MatchedBy = "vector"
)

type Memory

type Memory = artifact.Artifact[Content]

type OrganizeMode

type OrganizeMode string
const (
	OrganizeDefault   OrganizeMode = "default"
	OrganizeDedupe    OrganizeMode = "dedupe"
	OrganizeNormalize OrganizeMode = "normalize"
)

type Projection

type Projection struct {
	// contains filtered or unexported fields
}

Projection is rebuildable active-head search state. EntryVersion and vector values are copied at construction and access.

func NewProjection

func NewProjection(
	entry EntryVersion,
	searchableText string,
	embedding []float64,
	embeddingContentHash *string,
) (Projection, error)

func (Projection) Embedding

func (p Projection) Embedding() []float64

func (Projection) EmbeddingContentHash

func (p Projection) EmbeddingContentHash() *string

func (Projection) EntryVersion

func (p Projection) EntryVersion() EntryVersion

func (Projection) SearchableText

func (p Projection) SearchableText() string

type RememberMode

type RememberMode string
const (
	RememberAppend  RememberMode = "append"
	RememberExtract RememberMode = "extract"
	RememberAuto    RememberMode = "auto"
)

type RerankCandidate

type RerankCandidate struct {
	// contains filtered or unexported fields
}

func (RerankCandidate) Rank

func (c RerankCandidate) Rank() int

func (RerankCandidate) Text

func (c RerankCandidate) Text() string

type RerankDecision

type RerankDecision struct {
	// contains filtered or unexported fields
}

func (RerankDecision) DiscardedRankCount

func (d RerankDecision) DiscardedRankCount() int

func (RerankDecision) SelectedRanks

func (d RerankDecision) SelectedRanks() []int

func (RerankDecision) Usage

func (d RerankDecision) Usage() inference.Usage

func (RerankDecision) UsedFallback

func (d RerankDecision) UsedFallback() bool

type RerankInput

type RerankInput struct {
	// contains filtered or unexported fields
}

func (RerankInput) Candidates

func (i RerankInput) Candidates() []RerankCandidate

func (RerankInput) MarshalJSON

func (i RerankInput) MarshalJSON() ([]byte, error)

func (RerankInput) MaxResults

func (i RerankInput) MaxResults() int

func (RerankInput) Query

func (i RerankInput) Query() string

type RerankOutput

type RerankOutput struct {
	// contains filtered or unexported fields
}

func NewRerankOutput

func NewRerankOutput(selectedRanks []int) RerankOutput

func (RerankOutput) SelectedRanks

func (o RerankOutput) SelectedRanks() []int

type RerankTrace

type RerankTrace struct {
	PolicyID           string
	CandidateHits      []Hit
	SelectedRanks      []int
	DiscardedRankCount int
	UsedFallback       bool
	LatencyMS          float64
	Usage              inference.Usage
}

type Reranker

type Reranker interface {
	PolicyID() string
	Rerank(context.Context, string, []Hit, int) (RerankDecision, error)
}

type RevisionChanges

type RevisionChanges struct {
	MemoryRef artifact.Ref
	Changes   []Change
}

RevisionChanges is the compact change list for one exact Memory revision.

func (RevisionChanges) Clone

func (r RevisionChanges) Clone() RevisionChanges

type SearchChannels

type SearchChannels struct {
	FTS    []ChannelHit
	Vector []ChannelHit
}

SearchChannels preserves backend ordering before shared admission and RRF.

func (SearchChannels) Clone

func (c SearchChannels) Clone() SearchChannels

type SearchMode

type SearchMode string
const (
	SearchFTS    SearchMode = "fts"
	SearchVector SearchMode = "vector"
	SearchHybrid SearchMode = "hybrid"
	SearchAuto   SearchMode = "auto"
)

type SearchRequest

type SearchRequest struct {
	Query            string
	AnalyzedQuery    string
	Memories         []artifact.Ref
	CandidateLimit   int
	Mode             SearchMode
	QueryVector      []float64
	EmbeddingProfile *EmbeddingProfile
}

SearchRequest is the validated backend request after capability selection.

func (SearchRequest) Clone

func (r SearchRequest) Clone() SearchRequest

type SearchResult

type SearchResult struct {
	Mode   SearchMode
	Hits   []Hit
	Rerank *RerankTrace
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(backend Backend, options ServiceOptions) (*Service, error)

func (*Service) Apply

func (s *Service) Apply(ctx context.Context, plan WritePlan) (*Memory, error)

func (*Service) Changes

func (s *Service) Changes(ctx context.Context, value Memory, sinceRevision *int64) ([]RevisionChanges, error)

func (*Service) Entries

func (s *Service) Entries(ctx context.Context, value Memory) ([]EntryVersion, error)

func (*Service) Expand

func (s *Service) Expand(ctx context.Context, hits []Hit) ([]EntryVersion, error)

func (*Service) Forget

func (s *Service) Forget(ctx context.Context, value Memory, entries []EntryVersion, reason *string) (Memory, error)

func (*Service) Get

func (s *Service) Get(ctx context.Context, value Memory) (Memory, error)

func (*Service) Head

func (s *Service) Head(ctx context.Context, artifactID string) (Memory, error)

func (*Service) Latest

func (s *Service) Latest(ctx context.Context, value Memory) (Memory, error)

func (*Service) Organize

func (s *Service) Organize(ctx context.Context, value Memory, mode OrganizeMode) (Memory, error)

func (*Service) PlanRemember

func (s *Service) PlanRemember(
	ctx context.Context,
	base *Memory,
	sources []source.Value,
	artifacts []artifact.Snapshot,
	entries []EntryInput,
	mode RememberMode,
) (WritePlan, error)

func (*Service) Reactivate

func (s *Service) Reactivate(ctx context.Context, value Memory, entries []EntryVersion, reason *string) (Memory, error)

func (*Service) Remember

func (s *Service) Remember(
	ctx context.Context,
	base *Memory,
	sources []source.Value,
	artifacts []artifact.Snapshot,
	entries []EntryInput,
	mode RememberMode,
) (*Memory, error)

func (*Service) Revision

func (s *Service) Revision(ctx context.Context, ref artifact.Ref) (Memory, error)

func (*Service) Revisions

func (s *Service) Revisions(ctx context.Context, value Memory) ([]Memory, error)

func (*Service) Search

func (s *Service) Search(
	ctx context.Context,
	query string,
	memories []Memory,
	limit int,
	mode SearchMode,
) (SearchResult, error)

func (*Service) ValidateCitation

func (s *Service) ValidateCitation(ctx context.Context, citation Citation) (EntryVersion, error)

type ServiceOptions

type ServiceOptions struct {
	CandidatePipeline    CandidatePipeline
	EmbeddingModel       inference.EmbeddingModel
	Reranker             Reranker
	RerankCandidateLimit int
	SourceResolver       SourceResolver
	ArtifactResolver     ArtifactResolver
	IDFactory            IDFactory
	Clock                Clock
}

type SourceResolver

type SourceResolver interface {
	Get(context.Context, source.Value) (source.Value, error)
	Ref(source.Value) (source.Ref, error)
}

type WritePlan

type WritePlan struct {
	// contains filtered or unexported fields
}

func NewWritePlan

func NewWritePlan(result *Memory, commit *Commit) WritePlan

func (WritePlan) Commit

func (p WritePlan) Commit() *Commit

func (WritePlan) Result

func (p WritePlan) Result() *Memory

Directories

Path Synopsis
Package prompts owns the frozen Memory inference instructions.
Package prompts owns the frozen Memory inference instructions.

Jump to

Keyboard shortcuts

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