rerank

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rerank provides reranking implementations for retrieval results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain chains multiple rerankers together.

func NewChain

func NewChain(rerankers ...retrieve.Reranker) *Chain

NewChain creates a new reranker chain.

func (*Chain) Rerank

func (c *Chain) Rerank(ctx context.Context, q retrieve.Query, items []retrieve.ContextItem) ([]retrieve.ContextItem, error)

Rerank implements retrieve.Reranker.

type CrossEncoder

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

CrossEncoder implements reranking using a cross-encoder model.

func NewCrossEncoder

func NewCrossEncoder(cfg CrossEncoderConfig) *CrossEncoder

NewCrossEncoder creates a new cross-encoder reranker.

func (*CrossEncoder) Rerank

Rerank implements retrieve.Reranker.

type CrossEncoderConfig

type CrossEncoderConfig struct {
	// Scorer is the cross-encoder model to use.
	Scorer CrossEncoderScorer
	// TopK limits output to top K results after reranking.
	TopK int
	// MinScore filters results below this threshold.
	MinScore float64
}

CrossEncoderConfig configures the cross-encoder reranker.

type CrossEncoderScorer

type CrossEncoderScorer interface {
	// Score returns relevance scores for query-document pairs.
	Score(ctx context.Context, query string, documents []string) ([]float64, error)
	// Model returns the model name.
	Model() string
}

CrossEncoderScorer scores query-document pairs using a cross-encoder model.

type Heuristic

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

Heuristic implements heuristic-based reranking.

func NewHeuristic

func NewHeuristic(cfg HeuristicConfig) *Heuristic

NewHeuristic creates a new heuristic reranker.

func (*Heuristic) Rerank

Rerank implements retrieve.Reranker.

type HeuristicConfig

type HeuristicConfig struct {
	// Strategy is the scoring strategy.
	Strategy Strategy
	// Weights for different signals (e.g., "similarity", "recency", "popularity").
	Weights map[string]float64
	// TopK limits output.
	TopK int
	// MinScore threshold.
	MinScore float64
	// BoostExactMatch boosts items containing exact query matches.
	BoostExactMatch bool
	// ExactMatchBoost is the boost factor for exact matches.
	ExactMatchBoost float64
}

HeuristicConfig configures heuristic reranking.

type Strategy

type Strategy string

Strategy defines a reranking strategy.

const (
	// StrategyReciprocal uses reciprocal rank fusion.
	StrategyReciprocal Strategy = "reciprocal"
	// StrategyLinear uses linear score combination.
	StrategyLinear Strategy = "linear"
	// StrategyMax takes the maximum score.
	StrategyMax Strategy = "max"
)

Jump to

Keyboard shortcuts

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