recall

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SupersessionPenaltyFactor is the multiplicative penalty for memories that have
	// been superseded by another memory present in the same result set.
	SupersessionPenaltyFactor = 0.3

	// ConflictPenaltyFactor is the multiplicative penalty for memories with an
	// active (unresolved) conflict status.
	ConflictPenaltyFactor = 0.8
)

Variables

TypePriority maps memory types to their raw priority multipliers (before normalization).

Functions

func FormatWithConflictAnnotations added in v0.4.0

func FormatWithConflictAnnotations(results []models.RecallResult, budget int) string

FormatWithConflictAnnotations formats recall results with inline conflict annotations. Memories in an active conflict group are annotated with the short IDs of conflicting peers.

Types

type Reasoner added in v0.4.0

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

Reasoner uses Claude to re-rank recall results by genuine relevance to the query. It addresses the "similarity ≠ relevance" problem: vector similarity finds related content, but Claude can reason about which memories are truly useful.

On any API failure the Reasoner degrades gracefully and returns results in their original order so the caller always gets a usable response.

func NewReasoner added in v0.4.0

func NewReasoner(apiKey, model string, logger *slog.Logger) *Reasoner

NewReasoner creates a Reasoner backed by the Anthropic Claude API.

func (*Reasoner) ReRank added in v0.4.0

func (r *Reasoner) ReRank(ctx context.Context, query string, results []models.RecallResult, maxCandidates int) ([]models.RecallResult, error)

ReRank passes the top maxCandidates results to Claude and returns them reordered by relevance to query. Results beyond maxCandidates are appended unchanged after the re-ranked set.

If maxCandidates <= 0, defaultReasonerCandidates is used. On any error (API failure, unexpected response) the original order is returned.

type Recaller

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

Recaller performs multi-factor ranking of search results.

func NewRecaller

func NewRecaller(weights Weights, logger *slog.Logger) *Recaller

NewRecaller creates a new recaller with the given weights. If the weights are invalid, a warning is logged and defaults are used.

func (*Recaller) Rank

func (r *Recaller) Rank(results []models.SearchResult, project string, query string) []models.RecallResult

Rank re-ranks search results using multi-factor scoring. All component scores are normalized to [0,1] before weighting.

func (*Recaller) ShouldRerank added in v0.4.0

func (r *Recaller) ShouldRerank(results []models.RecallResult, threshold float64) bool

ShouldRerank returns true when the top-4 results are close enough in score that Claude re-ranking may improve ordering. Returns false when:

  • threshold is <= 0 (feature disabled)
  • fewer than 4 results are provided
  • the spread between results[0] and results[3] exceeds the threshold

type Weights

type Weights struct {
	Similarity    float64 `json:"similarity" mapstructure:"similarity"`
	Recency       float64 `json:"recency" mapstructure:"recency"`
	Frequency     float64 `json:"frequency" mapstructure:"frequency"`
	TypeBoost     float64 `json:"type_boost" mapstructure:"type_boost"`
	ScopeBoost    float64 `json:"scope_boost" mapstructure:"scope_boost"`
	Confidence    float64 `json:"confidence" mapstructure:"confidence"`
	Reinforcement float64 `json:"reinforcement" mapstructure:"reinforcement"`
	TagAffinity   float64 `json:"tag_affinity" mapstructure:"tag_affinity"`
}

Weights controls the relative importance of each ranking factor.

func DefaultWeights

func DefaultWeights() Weights

DefaultWeights returns sensible default ranking weights.

func (Weights) Validate added in v0.4.0

func (w Weights) Validate() error

Validate checks that the weights are non-negative and sum to approximately 1.0.

Jump to

Keyboard shortcuts

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