Documentation
¶
Overview ¶
Package rerank defines the provider-neutral protocol for ranking documents against one query. Results address the immutable input batch by index so the protocol does not duplicate document ownership or depend on a retrieval type.
Example ¶
package main
import (
"fmt"
"github.com/Tangerg/scope/core/rerank"
)
func main() {
request, err := rerank.NewRequest("capital of France", []string{
"Berlin is the capital of Germany.",
"Paris is the capital of France.",
})
if err != nil {
panic(err)
}
request.Options.Model = "provider-reranker"
fmt.Println(request.Query, len(request.Documents))
}
Output: capital of France 2
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model interface {
// Call ranks an immutable document batch for one query. It must not retain or
// mutate request and transfers ownership of the response to the caller.
Call(ctx context.Context, request *Request) (*Response, error)
}
Model is the complete provider-neutral reranking SPI. Implementations validate requests before I/O, reject explicit options they cannot represent, preserve context error identity, and return responses that pass ValidateFor.
type Options ¶
type Options struct {
Model string `json:"model"`
TopK *int `json:"top_k,omitzero"`
Extensions metadata.Extensions `json:"extensions,omitzero"`
}
Options holds per-request reranking configuration. A nil TopK inherits the configured default; without a default, every document is returned. A pointer to zero explicitly requests every document. Provider-specific controls remain in Extensions.
func (Options) MarshalJSON ¶
func (Options) ResultLimit ¶
func (*Options) UnmarshalJSON ¶
type Request ¶
type Request struct {
Query string `json:"query"`
Documents []string `json:"documents"`
Options Options `json:"options,omitzero"`
}
Request is one reranking call. Result indices address Documents in this immutable order.
func NewRequest ¶
NewRequest snapshots documents so result indices keep addressing the original inputs.
func (Request) MarshalJSON ¶
func (*Request) UnmarshalJSON ¶
type Response ¶
type Response struct {
Results []*Result `json:"results"`
Metadata *ResponseMetadata `json:"metadata,omitzero"`
}
Response is a relevance-descending subset of the input document indices.
func NewResponse ¶
func NewResponse(results []*Result, responseMetadata *ResponseMetadata) (*Response, error)
func (Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
func (*Response) ValidateFor ¶
type ResponseMetadata ¶
type ResponseMetadata struct {
Model string `json:"model"`
Usage *Usage `json:"usage,omitzero"`
Extra metadata.Map `json:"extra,omitzero"`
}
func (ResponseMetadata) MarshalJSON ¶
func (r ResponseMetadata) MarshalJSON() ([]byte, error)
func (*ResponseMetadata) UnmarshalJSON ¶
func (r *ResponseMetadata) UnmarshalJSON(data []byte) error
type Result ¶
Result relates one input document index to its normalized relevance. JSON requires both fields; neither may be absent or null.
func (Result) MarshalJSON ¶
func (*Result) UnmarshalJSON ¶
type Score ¶
type Score float64
Score is a normalized relevance value in [0, 1]. Its JSON value must be a number.
func (Score) MarshalJSON ¶
func (*Score) UnmarshalJSON ¶
type Usage ¶
type Usage struct {
InputTokens int64 `json:"input_tokens"`
}
Usage records a reported input token count. JSON requires input_tokens even when zero; unreported usage belongs to a nil ResponseMetadata.Usage.