rerank

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rerank scores search candidates with a cross-encoder: the second stage of retrieval, after the vector search has picked the candidates and before anything is truncated to the requested limit. Any hosted or local provider with an HTTP rerank endpoint works; the three request shapes in use are the API values below.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API string

API is the request shape a provider expects.

const (
	// APIGeneric is `{model, query, documents, top_n}` with a bearer token:
	// OpenRouter, Jina, vLLM, Text Embeddings Inference.
	APIGeneric API = "generic"
	// APIVoyage is `{model, query, documents, top_k, truncation}` with an
	// x-api-key header.
	APIVoyage API = "voyage"
	// APICohere is `{model, query, documents:[{text}], top_n}` with a bearer
	// token.
	APICohere API = "cohere"
)

func APIForHost

func APIForHost(baseURL string) API

APIForHost guesses the request shape from the endpoint's host.

type Config

type Config struct {
	// BaseURL is the API base the rerank route hangs off; empty means no
	// reranker.
	BaseURL string
	APIKey  string
	// Model is the provider's model name.
	Model string
	// API selects the request shape; "" means APIForHost of BaseURL.
	API API
	// Timeout bounds one call (30 s when zero).
	Timeout time.Duration
}

Config is a rerank endpoint.

type Provider

type Provider interface {
	Name() string
	Rerank(ctx context.Context, query string, texts []string) ([]Score, error)
}

Provider reranks texts for a query and returns the scores of the ones the provider kept, in the provider's order.

func New

func New(cfg *Config) (Provider, error)

New builds the HTTP reranker of a configuration; nil (and no error) when no endpoint is configured.

type Score

type Score struct {
	Index int
	Value float32
}

Score is one reranked candidate: its position in the input and its relevance (higher is better; the scale is the provider's).

Jump to

Keyboard shortcuts

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