memory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DualWriteDedupeThreshold is the semantic similarity cutoff used to suppress
	// near-duplicate legacy structured dual-write entries.
	DualWriteDedupeThreshold = 0.92
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InfoParser

type InfoParser interface {
	Parse(ctx context.Context, content string, maxFacts int) ([]ParsedFact, error)
}

func NewHeuristicInfoParser

func NewHeuristicInfoParser() InfoParser

func NewOllamaInfoParser

func NewOllamaInfoParser(baseURL, model string, timeout time.Duration, logger *log.Logger, verbose bool) (InfoParser, error)

func NewOpenRouterInfoParser

func NewOpenRouterInfoParser(client *openrouterclient.Client, logger *log.Logger, verbose bool) InfoParser

type MatchWeights

type MatchWeights struct {
	Recency      float64
	Relevance    float64
	Importance   float64
	QueryOverlap float64
	Routing      float64
}

type MultiHopOptions

type MultiHopOptions struct {
	EntityFactBridgeEnabled    bool
	LLMDecompositionEnabled    bool
	MaxDecompositionQueries    int
	EnablePairwiseRerank       bool
	TokenExpansionFallback     bool
	GraphPathEnabled           bool
	GraphMaxHops               int
	GraphSeedLimit             int
	GraphPathLimit             int
	GraphMinScore              float64
	GraphWeight                float64
	GraphTemporalValidity      bool
	GraphSingletonInvalidation bool
}

type MultiHopQueryDecomposer

type MultiHopQueryDecomposer interface {
	Decompose(ctx context.Context, query string, maxQueries int) ([]string, error)
}

func NewLLMMultiHopQueryDecomposer

func NewLLMMultiHopQueryDecomposer(
	generator llmPromptGenerator,
	logger *log.Logger,
	verbose bool,
) MultiHopQueryDecomposer

type ParsedFact

type ParsedFact struct {
	Content        string
	QueryViewText  string
	Kind           domain.MemoryKind
	Tags           []string
	Entity         string
	Relation       string
	Value          string
	AnswerMetadata domain.MemoryAnswerMetadata
}

type ParserOptions

type ParserOptions struct {
	Enabled                    bool
	Provider                   string
	Model                      string
	StoreRawTurn               bool
	MaxFacts                   int
	DedupeThreshold            float64
	UpdateThreshold            float64
	AnswerSpanRetentionEnabled bool
}

type PostprocessWorkerOptions

type PostprocessWorkerOptions struct {
	Enabled      bool
	PollInterval time.Duration
	BatchSize    int
	WorkerCount  int
	Lease        time.Duration
	MaxAttempts  int
	RetryBase    time.Duration
	RetryMax     time.Duration
}

func DefaultPostprocessWorkerOptions

func DefaultPostprocessWorkerOptions() PostprocessWorkerOptions

type RankingOptions

type RankingOptions struct {
	Algorithm string
	WAL       WALWeights
	Match     MatchWeights
}

type RerankOptions

type RerankOptions struct {
	Enabled  bool
	Provider string
	Window   int
	Blend    float64
}

type RetrievalBehaviorOptions

type RetrievalBehaviorOptions struct {
	AnswerTypeRoutingEnabled             bool
	EarlyRankRerankEnabled               bool
	TemporalResolverEnabled              bool
	OpenDomainAlternativeResolverEnabled bool
	ProfileSupportLinksEnabled           bool
	SearchTuning                         RetrievalSearchTuningOptions
}

type RetrievalSearchTuningOptions

type RetrievalSearchTuningOptions struct {
	AdaptiveQueryExpansionEnabled        bool
	AdaptiveQueryMaxExtraQueries         int
	AdaptiveQueryWeakLexicalThreshold    float64
	AdaptiveQueryPlanConfidenceThreshold float64
	CandidateWindowMultiplier            int
	CandidateWindowMin                   int
	CandidateWindowMax                   int
	CandidateWindowTemporalBoost         int
	CandidateWindowMultiHopBoost         int
	CandidateWindowFilterBoost           int
	EarlyRerankBaseWindow                int
	EarlyRerankMaxWindow                 int
}

type SearchDebugInfo

type SearchDebugInfo struct {
	Plan    SearchPlanDebug      `json:"plan"`
	Ranking []SearchRankingDebug `json:"ranking,omitempty"`
}

type SearchOptions

type SearchOptions struct {
	MinScore      float64
	Tiers         []domain.MemoryTier
	Kinds         []domain.MemoryKind
	RetrievalKind SearchRetrievalKind
	DisableTouch  bool
	Debug         bool
}

type SearchPlanDebug

type SearchPlanDebug struct {
	Intent           string   `json:"intent"`
	Confidence       float64  `json:"confidence"`
	AnswerType       string   `json:"answer_type,omitempty"`
	Entities         []string `json:"entities,omitempty"`
	Relations        []string `json:"relations,omitempty"`
	TimeConstraints  []string `json:"time_constraints,omitempty"`
	RequiredEvidence string   `json:"required_evidence,omitempty"`
	FallbackPath     []string `json:"fallback_path,omitempty"`
}

type SearchRankingDebug

type SearchRankingDebug struct {
	Rank         int     `json:"rank"`
	MemoryID     string  `json:"memory_id"`
	Kind         string  `json:"kind"`
	Tier         string  `json:"tier"`
	LexicalScore float64 `json:"lexical_score"`
	QueryOverlap float64 `json:"query_overlap"`
	RouteFit     float64 `json:"route_fit"`
}

type SearchRetrievalKind

type SearchRetrievalKind string
const (
	SearchRetrievalKindAuto   SearchRetrievalKind = "auto"
	SearchRetrievalKindVector SearchRetrievalKind = "vector"
	SearchRetrievalKindEntity SearchRetrievalKind = "entity"
)

type Service

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

func NewService

func NewService(
	repo domain.MemoryRepository,
	tenantRepo domain.TenantRepository,
	vector domain.VectorStore,
	embedder domain.Embedder,
	scorer domain.ImportanceScorer,
	options ...ServiceOption,
) *Service

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, tenantID, memoryID string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, tenantID, memoryID string) (*domain.Memory, error)

func (*Service) GetPostprocessJob

func (s *Service) GetPostprocessJob(ctx context.Context, jobID string) (*domain.MemoryPostprocessJob, error)

func (*Service) IngestAsync

func (s *Service) IngestAsync(
	ctx context.Context,
	in StoreInput,
	maxAttempts int,
) (domain.MemoryIngestReceipt, error)

func (*Service) IngestBatchAsync

func (s *Service) IngestBatchAsync(
	ctx context.Context,
	inputs []StoreInput,
	maxAttempts int,
) (domain.MemoryIngestReceipt, error)

func (*Service) List

func (s *Service) List(ctx context.Context, tenantID string, limit int) ([]domain.Memory, error)

func (*Service) ListPostprocessJobs

func (s *Service) ListPostprocessJobs(
	ctx context.Context,
	filter domain.MemoryPostprocessJobFilter,
) ([]domain.MemoryPostprocessJob, error)

func (*Service) Search

func (s *Service) Search(ctx context.Context, tenantID, query string, topK int) ([]domain.Memory, error)

func (*Service) SearchWithFilters

func (s *Service) SearchWithFilters(ctx context.Context, tenantID, query string, topK int, opts SearchOptions) ([]domain.Memory, error)

func (*Service) SearchWithFiltersDebug

func (s *Service) SearchWithFiltersDebug(
	ctx context.Context,
	tenantID, query string,
	topK int,
	opts SearchOptions,
) ([]domain.Memory, *SearchDebugInfo, error)

func (*Service) StartPostprocessWorkers

func (s *Service) StartPostprocessWorkers(
	parent context.Context,
	opts PostprocessWorkerOptions,
) (func(), error)

func (*Service) Store

func (s *Service) Store(ctx context.Context, in StoreInput) (domain.Memory, error)

func (*Service) StoreBatch

func (s *Service) StoreBatch(ctx context.Context, inputs []StoreInput) ([]domain.Memory, error)

type ServiceOption

type ServiceOption interface {
	// contains filtered or unexported methods
}

func WithDebug

func WithDebug(verbose bool, progress bool) ServiceOption

func WithEntityFactRepository

func WithEntityFactRepository(repo domain.EntityFactRepository) ServiceOption

func WithImplicitCanonicalKindsForEntityFacts

func WithImplicitCanonicalKindsForEntityFacts(enabled bool) ServiceOption

func WithInfoParser

func WithInfoParser(parser InfoParser) ServiceOption

func WithLogger

func WithLogger(logger *log.Logger) ServiceOption

func WithMultiHopQueryDecomposer

func WithMultiHopQueryDecomposer(decomposer MultiHopQueryDecomposer) ServiceOption

type StoreInput

type StoreInput struct {
	TenantID       string
	Content        string
	Tier           domain.MemoryTier
	Kind           domain.MemoryKind
	Tags           []string
	Source         string
	CreatedBy      domain.MemoryCreatedBy
	AnswerMetadata domain.MemoryAnswerMetadata
}

type StructuredMemoryOptions

type StructuredMemoryOptions struct {
	Enabled               bool
	DualWriteObservations bool
	DualWriteEvents       bool
	MaxObservations       int
}

type WALWeights

type WALWeights struct {
	Recency    float64
	Relevance  float64
	Importance float64
}

Jump to

Keyboard shortcuts

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