Documentation
¶
Overview ¶
Package memorykit defines the versioned domain contract for project memory.
The project-memory-v1 normalization policy preserves identities: keys are neither lowercased nor Unicode-normalized, and content is stored byte-for-byte.
Index ¶
- Variables
- func CountSearchTermHits(key, content string, words, grams []string) int
- func ExtractionCandidateID(jobID string, draft CandidateDraft) (string, error)
- func IsRecoverable(err error) bool
- func SearchTerms(text string) (words, grams []string)
- func ValidateCandidateDraft(draft CandidateDraft, limits Limits) error
- func ValidateCandidateQuery(query CandidateQuery, limits Limits) error
- func ValidateCommand(command VersionedCommand, limits Limits) error
- func ValidateCorrectRequest(request CorrectRequest, limits Limits) error
- func ValidateCreateRequest(request CreateRequest, limits Limits) error
- func ValidateListQuery(query ListQuery, limits Limits) error
- func ValidateMemoryID(id string) error
- func ValidatePendingEmbeddingQuery(query PendingEmbeddingQuery, limits Limits) error
- func ValidatePutEmbeddingRequest(request PutEmbeddingRequest, limits Limits) error
- func ValidateRevisionQuery(query RevisionQuery, limits Limits) error
- func ValidateSources(sources []Source, limits Limits) error
- type BackendError
- type Candidate
- type CandidateDraft
- type CandidateExtractor
- type CandidateQuery
- type CandidateSet
- type Channel
- type ChannelError
- type ContentValidator
- type CorrectRequest
- type CreateRequest
- type EmbedRequest
- type Embedder
- type EmbeddingInput
- type EmbeddingStore
- type EmbeddingWorker
- type EmbeddingWorkerConfig
- type EvalCase
- type EvalCorpus
- type EvalMemory
- type EvalReport
- type ExtractionJob
- type ExtractionJobStatus
- type ExtractionJobStore
- type ExtractionRequest
- type ExtractionWorker
- type ExtractionWorkerConfig
- type Kind
- type LifecycleStore
- type Limits
- type ListQuery
- type Memory
- type PendingEmbeddingQuery
- type PutEmbeddingRequest
- type RecallConfig
- type RecallItem
- type RecallPolicy
- type RecallRequest
- type RecallResult
- type RecallStore
- type Recaller
- type Revision
- type RevisionAction
- type RevisionQuery
- type Scope
- type Source
- type SourceReader
- type Status
- type Store
- type SubjectType
- type TokenCounter
- type TrustedProjection
- type VersionedCommand
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidScope = errors.New("invalid memory scope") ErrInvalidMemory = errors.New("invalid memory") ErrNotFound = errors.New("memory not found") ErrConflict = errors.New("memory version conflict") ErrNoExtractionJob = errors.New("no claimable extraction job") ErrInvalidRecallResult = errors.New("invalid memory recall result") ErrRecallDependency = errors.New("memory recall dependency failure") )
Functions ¶
func CountSearchTermHits ¶
CountSearchTermHits counts how many query terms a memory matches: words against the memory's own words, grams as substrings of its text.
func ExtractionCandidateID ¶
func ExtractionCandidateID(jobID string, draft CandidateDraft) (string, error)
ExtractionCandidateID derives a candidate's ID from its job and content, so a retry that extracts the same draft, in any position, replays the same create instead of colliding with a different draft.
func IsRecoverable ¶
func SearchTerms ¶
SearchTerms splits recall text into the terms every RecallStore matches the same way. Words are lowercase runs of letters and digits, as PostgreSQL's 'simple' text-search configuration produces them. Chinese and Japanese are written without spaces, so their runs become overlapping two-character grams (a lone character stays a unigram) that stores match as substrings.
func ValidateCandidateDraft ¶
func ValidateCandidateDraft(draft CandidateDraft, limits Limits) error
ValidateCandidateDraft delegates field validation to the create contract while fixing the lifecycle state to candidate and using validation-only identities.
func ValidateCandidateQuery ¶
func ValidateCandidateQuery(query CandidateQuery, limits Limits) error
ValidateCandidateQuery validates both shared filters and channel-specific inputs.
func ValidateCommand ¶
func ValidateCommand(command VersionedCommand, limits Limits) error
func ValidateCorrectRequest ¶
func ValidateCorrectRequest(request CorrectRequest, limits Limits) error
func ValidateCreateRequest ¶
func ValidateCreateRequest(request CreateRequest, limits Limits) error
func ValidateListQuery ¶
func ValidateMemoryID ¶
ValidateMemoryID accepts only the canonical lowercase UUID text form. Storage implementations must not normalize alternate representations implicitly.
func ValidatePendingEmbeddingQuery ¶
func ValidatePendingEmbeddingQuery(query PendingEmbeddingQuery, limits Limits) error
func ValidatePutEmbeddingRequest ¶
func ValidatePutEmbeddingRequest(request PutEmbeddingRequest, limits Limits) error
func ValidateRevisionQuery ¶
func ValidateRevisionQuery(query RevisionQuery, limits Limits) error
func ValidateSources ¶
Types ¶
type BackendError ¶
func (*BackendError) Error ¶
func (e *BackendError) Error() string
func (*BackendError) Unwrap ¶
func (e *BackendError) Unwrap() error
type CandidateDraft ¶
type CandidateDraft struct {
Kind Kind `json:"kind"`
Key string `json:"key"`
Content string `json:"content"`
ValidFrom time.Time `json:"valid_from,omitempty"`
ValidUntil time.Time `json:"valid_until,omitempty"`
Importance int `json:"importance,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
}
CandidateDraft is untrusted extracted content that has not been persisted or activated.
type CandidateExtractor ¶
type CandidateExtractor interface {
Extract(context.Context, ExtractionRequest) ([]CandidateDraft, error)
}
type CandidateQuery ¶
type CandidateSet ¶
type CandidateSet struct {
Exact, FullText, Vector []Candidate
}
type ChannelError ¶
func (*ChannelError) Error ¶
func (e *ChannelError) Error() string
func (*ChannelError) Unwrap ¶
func (e *ChannelError) Unwrap() error
type ContentValidator ¶
type CorrectRequest ¶
type CreateRequest ¶
type EmbedRequest ¶
type Embedder ¶
type Embedder interface {
Embed(context.Context, EmbedRequest) ([][]float32, error)
}
type EmbeddingInput ¶
type EmbeddingStore ¶
type EmbeddingStore interface {
PendingEmbeddings(context.Context, PendingEmbeddingQuery) ([]EmbeddingInput, error)
PutEmbedding(context.Context, PutEmbeddingRequest) error
}
type EmbeddingWorker ¶
type EmbeddingWorker struct {
// contains filtered or unexported fields
}
func NewEmbeddingWorker ¶
func NewEmbeddingWorker(config EmbeddingWorkerConfig) (*EmbeddingWorker, error)
type EmbeddingWorkerConfig ¶
type EmbeddingWorkerConfig struct {
Store EmbeddingStore
Embedder Embedder
ProfileID string
Dimensions int
BatchSize int
}
func (EmbeddingWorkerConfig) Validate ¶
func (c EmbeddingWorkerConfig) Validate() error
Validate rejects incomplete worker configuration before background work starts.
type EvalCorpus ¶
type EvalCorpus struct {
Version string `json:"version"`
Memories []EvalMemory `json:"memories"`
Cases []EvalCase `json:"cases"`
}
type EvalMemory ¶
type EvalReport ¶
type ExtractionJob ¶
type ExtractionJobStatus ¶
type ExtractionJobStatus string
const ( ExtractionPending ExtractionJobStatus = "pending" ExtractionLeased ExtractionJobStatus = "leased" ExtractionCompleted ExtractionJobStatus = "completed" ExtractionFailed ExtractionJobStatus = "failed" )
type ExtractionJobStore ¶
type ExtractionJobStore interface {
EnqueueExtraction(context.Context, ExtractionJob) error
ClaimExtraction(context.Context, string, time.Duration, int, time.Time) (ExtractionJob, error)
CompleteExtraction(context.Context, string, string, int, time.Time) error
FailExtraction(context.Context, string, string, int, string, int, time.Time) error
}
type ExtractionRequest ¶
type ExtractionWorker ¶
type ExtractionWorker struct {
// contains filtered or unexported fields
}
func NewExtractionWorker ¶
func NewExtractionWorker(config ExtractionWorkerConfig) (*ExtractionWorker, error)
type ExtractionWorkerConfig ¶
type ExtractionWorkerConfig struct {
Jobs ExtractionJobStore
Memories LifecycleStore
Reader SourceReader
Extractor CandidateExtractor
ValidateContent ContentValidator
Limits Limits
WorkerID string
LeaseDuration time.Duration
MaxAttempts int
Now func() time.Time
}
func (ExtractionWorkerConfig) Validate ¶
func (c ExtractionWorkerConfig) Validate() error
type LifecycleStore ¶
type LifecycleStore interface {
Create(context.Context, CreateRequest) (Memory, error)
Get(context.Context, Scope, string) (Memory, error)
Sources(context.Context, Scope, string) ([]Source, error)
List(context.Context, ListQuery) ([]Memory, error)
Activate(context.Context, VersionedCommand) (Memory, error)
Correct(context.Context, CorrectRequest) (Memory, error)
Dismiss(context.Context, VersionedCommand) (Memory, error)
Forget(context.Context, VersionedCommand) (Memory, error)
Erase(context.Context, VersionedCommand) error
Revisions(context.Context, RevisionQuery) ([]Revision, error)
}
type Limits ¶
type Memory ¶
type Memory struct {
ID, Key, Content, SourceAgentID, CreatedBy, IdempotencyKey string
Scope Scope
Kind Kind
Status Status
ValidFrom, ValidUntil time.Time
Importance int
Confidence float64
Version int64
CreatedAt, UpdatedAt time.Time
}
func ProjectTrusted ¶
func ProjectTrusted( ctx context.Context, store LifecycleStore, validator ContentValidator, limits Limits, projection TrustedProjection, ) (Memory, error)
ProjectTrusted maps an already-approved deterministic event directly to an active memory. It never invokes a model or converts candidate state.
type PendingEmbeddingQuery ¶
type PutEmbeddingRequest ¶
type RecallConfig ¶
type RecallConfig struct {
Store RecallStore
Embedder Embedder
CountTokens TokenCounter
Policy RecallPolicy
}
type RecallItem ¶
type RecallPolicy ¶
type RecallPolicy struct {
Version string
ExactLimit, FullTextLimit, VectorLimit int
RRFK float64
MinVectorSimilarity float64
MaxItems, MaxTokens int
MaxQueryRunes, MaxKeys int
Deadline time.Duration
EmbeddingProfileID string
EmbeddingDimensions int
}
func (RecallPolicy) Validate ¶
func (p RecallPolicy) Validate() error
Validate rejects partial policies so recall behavior is fixed at startup.
type RecallRequest ¶
type RecallResult ¶
type RecallResult struct {
Items []RecallItem
DegradedChannels []Channel
PolicyVersion string
}
type RecallStore ¶
type RecallStore interface {
SearchCandidates(context.Context, CandidateQuery) (CandidateSet, error)
}
type Recaller ¶
type Recaller struct {
// contains filtered or unexported fields
}
func NewRecaller ¶
func NewRecaller(config RecallConfig) (*Recaller, error)
func (*Recaller) MaxQueryRunes ¶
MaxQueryRunes exposes only the immutable query bound captured at construction.
func (*Recaller) Recall ¶
func (r *Recaller) Recall(ctx context.Context, request RecallRequest) (RecallResult, error)
type RevisionAction ¶
type RevisionAction string
const ( RevisionCreate RevisionAction = "create" RevisionActivate RevisionAction = "activate" RevisionCorrect RevisionAction = "correct" RevisionSupersede RevisionAction = "supersede" RevisionForget RevisionAction = "forget" RevisionErase RevisionAction = "erase" RevisionDismiss RevisionAction = "dismiss" )
type RevisionQuery ¶
type Scope ¶
type Scope struct {
TenantID string
SubjectType SubjectType
SubjectID string
}
type SourceReader ¶
type Store ¶
type Store interface {
LifecycleStore
RecallStore
EmbeddingStore
}
type SubjectType ¶
type SubjectType string
const ( SubjectProject SubjectType = "project" SubjectUser SubjectType = "user" )
type TokenCounter ¶
type TrustedProjection ¶
type TrustedProjection struct {
Create CreateRequest
EventID string
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storetest defines reusable conformance tests for lifecycle stores.
|
Package storetest defines reusable conformance tests for lifecycle stores. |