rerank

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package rerank is the BYOAI cross-encoder layer. Like embeddings, Mesh never runs inference itself: it POSTs (query, candidate documents) to an endpoint the operator controls and gets back a relevance score per document. A cross-encoder reads the query and a document jointly, so it is a sharper relevance signal than the bi-encoder vector cosine - the lever for top-1 precision (answer@1). It is a mechanical scoring transform, not reasoning AI; the agent is still the librarian. The endpoint can be fully local and sovereign (a self-hosted ONNX cross-encoder, see tools/rerank-server) or any cloud rerank API - the wire format is the same.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTP

type HTTP struct {
	Endpoint string
	ModelID  string
	Key      string // bearer token; empty for keyless local endpoints
	Client   *http.Client
}

HTTP speaks the de-facto-standard rerank contract shared by Cohere (/v2/rerank), Jina (/v1/rerank), Voyage, and self-hosted servers:

POST {Endpoint}  {"model","query","documents":[...],"top_n"?}
-> {"results":[{"index","relevance_score"}, ...]}  (sorted desc by score)

Endpoint is the full POST URL (not a base), because the path differs per provider. Results are returned in the request's document order regardless of the response order, so the caller can index straight back into its candidates.

func NewHTTP

func NewHTTP(endpoint, model, key string) *HTTP

func (*HTTP) Model

func (h *HTTP) Model() string

func (*HTTP) Rerank

func (h *HTTP) Rerank(ctx context.Context, query string, docs []string) ([]Result, error)

type Reranker

type Reranker interface {
	Rerank(ctx context.Context, query string, docs []string) ([]Result, error)
	Model() string
}

Reranker scores candidate documents against a query. Implementations must be deterministic for a given model so retrieval stays reproducible.

type Result

type Result struct {
	Index int
	Score float64
}

Result is one document's rerank score. Index is the document's position in the slice passed to Rerank; Score is the cross-encoder relevance (higher = more relevant). Scores are not normalized to any fixed range across models, so callers should rank by order or min-max normalize, never compare raw scores across endpoints.

type Stub

type Stub struct{ M string }

Stub is a deterministic, network-free reranker for tests and offline demos. It scores by query/document token overlap (Jaccard-ish). It is NOT a real cross-encoder: it exercises the rerank plumbing (ordering, integration, budget) but never proves retrieval quality.

func (Stub) Model

func (s Stub) Model() string

func (Stub) Rerank

func (s Stub) Rerank(_ context.Context, query string, docs []string) ([]Result, error)

Jump to

Keyboard shortcuts

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