search

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package search fuses results from multiple retrieval strategies (vector, keyword) into a single ranking, via either Reciprocal Rank Fusion (Fuse) or convex-combination score fusion (FuseScores), then re-ranks the result.

Index

Constants

View Source
const DefaultFusionAlpha = 0.5

DefaultFusionAlpha is the vector-leg weight in FuseScores; the keyword leg gets 1-alpha. 0.5 weights both legs equally.

View Source
const DefaultRRFK = 5.0

DefaultRRFK is the RRF damping constant; larger values flatten the contribution of top ranks. The classic value is 60, but with deep per-leg pools that lets many both-leg candidates outscore a memory ranked first in a single leg (2/(60+20) > 1/(60+0)); a steeper decay keeps single-leg hits dominant. 5 is at the low end of the [2,5] plateau measured on LongMemEval-S and LoCoMo.

Variables

View Source
var DefaultRerankWeights = RerankWeights{Relevance: 0.80, Recency: 0.05, Importance: 0.15}

DefaultRerankWeights is the production composite. Recency is a deliberately light tie-breaker: benchmarking on LongMemEval-S showed that heavier recency weighting buries correct-but-older memories (the gold session is not always the most recent), so relevance dominates and recency only decides near-ties.

Functions

func Dedup

func Dedup(results []store.Scored, limit int) []store.Scored

Dedup drops results whose normalized content matches an earlier (higher-ranked) result, keeping the first occurrence. It preserves order and returns at most limit results (limit <= 0 means no cap).

func Fuse

func Fuse(lists [][]store.Scored, k int, rrfK float64) []store.Scored

Fuse combines several best-first result lists into one ranking via Reciprocal Rank Fusion: each memory's fused score is the sum over lists of 1/(rrfK + rank), where rank is its 0-based position in that list. Memories are deduplicated by ID. The top k are returned, best-first.

func FuseScores

func FuseScores(lists [][]store.Scored, weights []float64, k int) []store.Scored

FuseScores combines best-first result lists by a weighted sum of their min-max-normalized scores (relative score fusion): within each list the scores are scaled so the best is 1 and the worst 0, then each memory's normalized scores are summed, weighted per list. Unlike RRF this preserves score magnitude, so a leg's standout hit outranks one that is middling in both legs. weights align with lists by index; absent weights default to 1. The top k are returned best-first (k <= 0 returns all); ties keep first-seen order.

func Rerank

func Rerank(results []store.Scored, now time.Time) []store.Scored

Rerank re-scores a fused result list with the default composite weights.

func RerankWith

func RerankWith(results []store.Scored, now time.Time, w RerankWeights) []store.Scored

RerankWith re-scores a fused result list with a composite of normalized relevance, access recency, and stored importance, then returns it best-first. The input Score is treated as the relevance signal (e.g. an RRF score) and is normalized by the maximum in the set so it mixes sanely with the [0,1] recency/importance factors. Order is stable for equal composite scores.

Types

type RerankWeights

type RerankWeights struct {
	Relevance, Recency, Importance float64
}

RerankWeights weights the composite ranking signals. Relevance (query similarity) dominates; recency and importance are secondary tie-breakers so a fresh or explicitly-important memory can edge a marginally-more-similar one.

Jump to

Keyboard shortcuts

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