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 ¶
- Variables
- type Model
- type ModelFunc
- type Options
- func (o Options) Clone() Options
- func (Options) JSONSchemaModel() any
- func (o Options) MarshalJSON() ([]byte, error)
- func (o Options) Resolve(override Options) (Options, error)
- func (o Options) ResultLimit(documentCount int) int
- func (o *Options) UnmarshalJSON(data []byte) error
- func (o Options) Validate() error
- type Request
- type Response
- type ResponseMetadata
- type Result
- type Score
- type Usage
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. Failures use github.com/Tangerg/scope/core/invocation.ClassifyFailure for evidence about the complete call. A nested failure cannot prove that earlier provider work did not run, and no failure kind authorizes retry.
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 positive TopK caps the number of results, so a request with fewer documents returns every one. 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) JSONSchemaModel ¶ added in v0.61.0
func (Options) MarshalJSON ¶
func (Options) ResultLimit ¶
ResultLimit is the exact number of results a response ranking documentCount documents holds under these options.
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) Clone ¶ added in v0.60.0
Clone keeps the submitted request independent of the model's working copy.
func (Request) JSONSchemaModel ¶ added in v0.61.0
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) JSONSchemaModel ¶ added in v0.61.0
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) JSONSchemaModel ¶ added in v0.61.0
func (ResponseMetadata) JSONSchemaModel() any
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 model-native relevance. JSON requires both fields; neither may be absent or null.
func (Result) JSONSchemaModel ¶ added in v0.61.0
func (Result) MarshalJSON ¶
func (*Result) UnmarshalJSON ¶
type Score ¶
type Score float64
Score preserves a model's finite relevance value, with higher values ranking first. Its scale is model- and query-dependent, so it is not a probability and must not be compared across models or queries. JSON requires a number.
func (Score) JSONSchemaModel ¶ added in v0.61.0
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.