Documentation
¶
Overview ¶
Package memory implements the Memory Artifact family and deterministic retrieval behavior.
Index ¶
- Constants
- func AdmitsFTSText(query, text string) bool
- func AnalyzeText(value string) string
- func CanonicalEmbedding(values []float64, dimension int, normalization string) ([]float64, error)
- func CanonicalJSON(value any) ([]byte, error)
- func ContentBytes(content Content) ([]byte, error)
- func ContentHash(content Content) (string, error)
- func EmbeddingContentHash(profile EmbeddingProfile, entryContentHash string) (string, error)
- func EntryContentBytes(kind, text string, sourceRefs []source.Ref, artifactRefs []artifact.Ref) ([]byte, error)
- func EntryContentHash(kind, text string, sourceRefs []source.Ref, artifactRefs []artifact.Ref) (string, error)
- func ExtractionInstructions(profile ExtractionProfile) (string, error)
- func ExtractionInstructionsVersion(profile ExtractionProfile) (string, error)
- func FTSMatchQuery(value string) (string, bool)
- func NewExtractionPromptedGenerator(model inference.TextModel, profile ExtractionProfile, limits *inference.Limits, ...) (*inference.PromptedGenerator[ExtractionInput, ExtractionOutput], error)
- func NewRerankPromptedGenerator(model inference.TextModel, limits *inference.Limits) (*inference.PromptedGenerator[RerankInput, RerankOutput], error)
- func NormalizeEmbedding(values []float64, dimension int) ([]float64, error)
- func NormalizeKind(value string) (string, error)
- func NormalizeReason(value *string) (*string, error)
- func NormalizeText(value string) (string, error)
- func ValidateContentHash(value string) (string, error)
- func ValidateEmbedding(values []float64, dimension int) ([]float64, error)
- func ValidateIdentifier(value string) (string, error)
- type ArtifactResolver
- type Backend
- type BackendConfigurationError
- type CandidatePipeline
- type CandidateRequest
- type CanonicalError
- type Capabilities
- type CapabilityNotSupportedError
- type Change
- type ChangeOp
- type ChannelHit
- type Citation
- type Clock
- type Commit
- type Content
- type ContentEvidenceProjector
- type DefaultEvidenceProjector
- type Draft
- type EmbeddingProfile
- type EntryInactiveError
- type EntryInput
- type EntryNotFoundError
- type EntryState
- type EntryVersion
- type EvidenceProjectionError
- type EvidenceProjector
- type ExtractionCandidate
- type ExtractionCurrentEntry
- type ExtractionEvidence
- type ExtractionInput
- type ExtractionIntent
- type ExtractionOutput
- type ExtractionProfile
- type Hit
- type IDFactory
- type InvalidCandidateError
- type InvalidCitationError
- type InvalidEmbeddingError
- type InvalidEvidenceError
- type InvalidOperationError
- type LLMCandidatePipeline
- type LLMReranker
- type Manifest
- type ManifestEntry
- type MatchedBy
- type Memory
- type OrganizeMode
- type Projection
- type RememberMode
- type RerankCandidate
- type RerankDecision
- type RerankInput
- type RerankOutput
- type RerankTrace
- type Reranker
- type RevisionChanges
- type SearchChannels
- type SearchMode
- type SearchRequest
- type SearchResult
- type Service
- func (s *Service) Apply(ctx context.Context, plan WritePlan) (*Memory, error)
- func (s *Service) Changes(ctx context.Context, value Memory, sinceRevision *int64) ([]RevisionChanges, error)
- func (s *Service) Entries(ctx context.Context, value Memory) ([]EntryVersion, error)
- func (s *Service) Expand(ctx context.Context, hits []Hit) ([]EntryVersion, error)
- func (s *Service) Forget(ctx context.Context, value Memory, entries []EntryVersion, reason *string) (Memory, error)
- func (s *Service) Get(ctx context.Context, value Memory) (Memory, error)
- func (s *Service) Head(ctx context.Context, artifactID string) (Memory, error)
- func (s *Service) Latest(ctx context.Context, value Memory) (Memory, error)
- func (s *Service) Organize(ctx context.Context, value Memory, mode OrganizeMode) (Memory, error)
- func (s *Service) PlanRemember(ctx context.Context, base *Memory, sources []source.Value, ...) (WritePlan, error)
- func (s *Service) Reactivate(ctx context.Context, value Memory, entries []EntryVersion, reason *string) (Memory, error)
- func (s *Service) Remember(ctx context.Context, base *Memory, sources []source.Value, ...) (*Memory, error)
- func (s *Service) Revision(ctx context.Context, ref artifact.Ref) (Memory, error)
- func (s *Service) Revisions(ctx context.Context, value Memory) ([]Memory, error)
- func (s *Service) Search(ctx context.Context, query string, memories []Memory, limit int, ...) (SearchResult, error)
- func (s *Service) ValidateCitation(ctx context.Context, citation Citation) (EntryVersion, error)
- type ServiceOptions
- type SourceResolver
- type WritePlan
Constants ¶
const Family = "memory"
Variables ¶
This section is empty.
Functions ¶
func AdmitsFTSText ¶
func AnalyzeText ¶
func CanonicalEmbedding ¶
func CanonicalJSON ¶
func ContentBytes ¶
func ContentHash ¶
func EmbeddingContentHash ¶
func EmbeddingContentHash(profile EmbeddingProfile, entryContentHash string) (string, error)
func EntryContentBytes ¶
func EntryContentHash ¶
func ExtractionInstructions ¶
func ExtractionInstructions(profile ExtractionProfile) (string, error)
func ExtractionInstructionsVersion ¶
func ExtractionInstructionsVersion(profile ExtractionProfile) (string, error)
func FTSMatchQuery ¶
func NewExtractionPromptedGenerator ¶
func NewExtractionPromptedGenerator( model inference.TextModel, profile ExtractionProfile, limits *inference.Limits, settings inference.GenerationSettings, ) (*inference.PromptedGenerator[ExtractionInput, ExtractionOutput], error)
func NewRerankPromptedGenerator ¶
func NewRerankPromptedGenerator( model inference.TextModel, limits *inference.Limits, ) (*inference.PromptedGenerator[RerankInput, RerankOutput], error)
func NormalizeEmbedding ¶
func NormalizeKind ¶
func NormalizeReason ¶
func NormalizeText ¶
func ValidateContentHash ¶
func ValidateIdentifier ¶
Types ¶
type ArtifactResolver ¶
type Backend ¶
type Backend interface {
Capabilities() Capabilities
Get(context.Context, artifact.Ref) (Memory, error)
Latest(context.Context, string) (Memory, error)
Entries(context.Context, artifact.Ref) ([]EntryVersion, error)
Projections(context.Context, artifact.Ref) ([]Projection, error)
Commit(context.Context, Commit) (Memory, error)
Changes(context.Context, artifact.Ref, *int64) ([]RevisionChanges, error)
VectorComplete(context.Context, []artifact.Ref, EmbeddingProfile) (bool, error)
Search(context.Context, SearchRequest) (SearchChannels, error)
Expand(context.Context, []Hit) ([]EntryVersion, error)
}
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 ¶
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 ¶
func (*CapabilityNotSupportedError) Error ¶
func (e *CapabilityNotSupportedError) Error() string
type Change ¶
type Change struct {
// contains filtered or unexported fields
}
func (Change) FromEntryVersionID ¶
func (Change) ToEntryVersionID ¶
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 (ChannelHit) Clone ¶
func (h ChannelHit) Clone() ChannelHit
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) ContentHash ¶
func (Commit) EntryVersions ¶
func (c Commit) EntryVersions() []EntryVersion
func (Commit) Projections ¶
func (c Commit) Projections() []Projection
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 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 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 (c ExtractionCandidate) Intent() ExtractionIntent
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)
type InvalidCandidateError ¶
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 NewLLMCandidatePipeline ¶
func NewLLMCandidatePipeline( generator inference.StructuredGenerator[ExtractionInput, ExtractionOutput], projector EvidenceProjector, ) (*LLMCandidatePipeline, error)
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 NewLLMReranker ¶
func NewLLMReranker( generator inference.StructuredGenerator[RerankInput, RerankOutput], ) (*LLMReranker, error)
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
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 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 RevisionChanges ¶
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) PlanRemember ¶
func (*Service) Reactivate ¶
func (*Service) Search ¶
func (s *Service) Search( ctx context.Context, query string, memories []Memory, limit int, mode SearchMode, ) (SearchResult, error)
func (*Service) ValidateCitation ¶
type ServiceOptions ¶
type ServiceOptions struct {
CandidatePipeline CandidatePipeline
EmbeddingModel inference.EmbeddingModel
Reranker Reranker
RerankCandidateLimit int
SourceResolver SourceResolver
ArtifactResolver ArtifactResolver
IDFactory IDFactory
Clock Clock
}