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 ModelFunc ¶
ModelFunc lets an ordinary function satisfy Model without declaring a named type, which is what keeps middleware and test doubles from each inventing their own adapter.
type Options ¶
type Options struct {
Model string `json:"model"`
TopK int `json:"top_k,omitempty"`
Extensions metadata.Extensions `json:"extensions,omitzero"`
}
Options holds per-request reranking configuration. TopK zero means 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 binds the query and its candidate set together because a rerank result is addressed by position into that exact slice. Accepting them separately would let a caller score one list and index into another.
func (Request) MarshalJSON ¶
func (*Request) UnmarshalJSON ¶
type Response ¶
type Response struct {
Results []*Result `json:"results"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
}
Response is a relevance-descending subset of the input document indices.
func NewResponse ¶
func NewResponse(results []*Result, responseMetadata *ResponseMetadata) (*Response, error)
NewResponse validates a complete provider result at the protocol boundary.
func (Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
func (*Response) ValidateFor ¶
type ResponseMetadata ¶
type ResponseMetadata struct {
Model string `json:"model"`
Usage *Usage `json:"usage,omitempty"`
Extra metadata.Map `json:"extra,omitzero"`
}
ResponseMetadata records the served model, portable usage, and open provider response metadata.
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.
func NewResult ¶
NewResult addresses a document by its index in the request rather than carrying the document itself. Repeating the text would let a response disagree with the request it answers, and would pay to move the corpus back across the wire.
func (Result) MarshalJSON ¶
func (*Result) UnmarshalJSON ¶
type Score ¶
type Score float64
Score is a normalized relevance value in [0, 1].