rerank

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package rerank adapts rerank models to the rag Refiner contract. It validates model indices and resolves them against the original candidate order, preserving document identity and result ownership.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNilModel = errors.New("rag: rerank model must not be nil")

Functions

This section is empty.

Types

type Refiner

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

Refiner adapts a reranking model to the Refiner lifecycle. It formats candidates once and resolves returned indices against the immutable input snapshot.

Example
package main

import (
	"context"
	"fmt"

	"github.com/Tangerg/scope/core/document"
	"github.com/Tangerg/scope/core/rerank"
	"github.com/Tangerg/scope/rag"

	ragrerank "github.com/Tangerg/scope/rag/rerank"
)

func main() {
	model := rerank.ModelFunc(func(context.Context, *rerank.Request) (*rerank.Response, error) {
		return &rerank.Response{Results: []*rerank.Result{{Index: 0, Score: 0.9}}}, nil
	})
	refiner, err := ragrerank.NewRefiner(ragrerank.RefinerConfig{Model: model, TopK: 1})
	if err != nil {
		panic(err)
	}
	query, err := rag.NewQuery("Go design")
	if err != nil {
		panic(err)
	}
	doc, err := document.NewDocument("Go favors explicit composition.", nil)
	if err != nil {
		panic(err)
	}
	result, err := refiner.Refine(context.Background(), query, rag.Candidates{{Document: doc}})
	if err != nil {
		panic(err)
	}
	fmt.Println(result[0].Score)
}
Output:
0.9

func NewRefiner

func NewRefiner(config RefinerConfig) (*Refiner, error)

func (*Refiner) Refine

func (r *Refiner) Refine(ctx context.Context, query rag.Query, candidates rag.Candidates) (rag.Candidates, error)

type RefinerConfig

type RefinerConfig struct {
	Model corererank.Model
	// Formatter defaults to [document.TextFormatter], which rejects media with
	// [document.ErrUnsupportedMedia].
	Formatter document.Formatter
	// TopK explicitly caps results; zero requests every candidate, including
	// when the model has a configured default limit.
	TopK int
}

func (RefinerConfig) Validate

func (r RefinerConfig) Validate() error

Jump to

Keyboard shortcuts

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