Documentation
¶
Overview ¶
Package rerank provides reranking implementations for Dory. Each implementation satisfies the dory.Reranker interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrossEncoder ¶
type CrossEncoder struct {
// contains filtered or unexported fields
}
CrossEncoder reranks retrieved units by scoring each query-document pair with a cross-encoder model, then sorting by the new scores.
func NewCrossEncoder ¶
func NewCrossEncoder(config CrossEncoderConfig) *CrossEncoder
NewCrossEncoder creates a new CrossEncoder reranker from the given config.
func (*CrossEncoder) Rerank ¶
func (ce *CrossEncoder) Rerank(ctx context.Context, query string, units []dory.RetrievedUnit) ([]dory.RetrievedUnit, error)
Rerank scores each unit concurrently against the query using the configured ScoreFunc, sorts by descending score, and applies TopK and Threshold filtering.
type CrossEncoderConfig ¶
type CrossEncoderConfig struct {
// ScoreFunc scores a single query-document pair and returns a
// relevance score. This is typically backed by a cross-encoder
// model API call.
ScoreFunc func(ctx context.Context, query string, document string) (float64, error)
// TopK limits the number of results returned. Zero means return all.
TopK int
// Threshold is the minimum score a unit must reach to be included
// in the results. Defaults to 0.
Threshold float64
}
CrossEncoderConfig configures a CrossEncoder reranker.
type LostInTheMiddle ¶
type LostInTheMiddle struct{}
LostInTheMiddle reorders units so the most relevant items appear at the edges (beginning and end) of the result list. This is based on the finding that LLMs attend more to tokens at the beginning and end of their context window, so placing the best results there improves downstream answer quality.
It does not change scores — only the ordering.
func NewLostInTheMiddle ¶
func NewLostInTheMiddle() *LostInTheMiddle
NewLostInTheMiddle creates a new LostInTheMiddle reranker.
func (*LostInTheMiddle) Rerank ¶
func (l *LostInTheMiddle) Rerank(_ context.Context, _ string, units []dory.RetrievedUnit) ([]dory.RetrievedUnit, error)
Rerank reorders the units so the highest-scored items occupy the first and last positions, the next-highest occupy positions 2 and N-1, and so on — placing the weakest items in the middle.