Documentation
¶
Overview ¶
Package reranking provides cross-encoder reranking for search results.
Package reranking provides cross-encoder reranking for search results.
Index ¶
- Constants
- type APIConfig
- type APIService
- func (s *APIService) Close() error
- func (s *APIService) Rerank(query string, candidates []Candidate, limit int) ([]RerankResult, error)
- func (s *APIService) RerankByScore(query string, candidates []Candidate, limit int) ([]RerankResult, error)
- func (s *APIService) Score(query, document string) (rawScore, normalizedScore float64, err error)
- type Candidate
- type RerankResult
- type Reranker
Constants ¶
const ( // DefaultCandidateLimit is the default number of candidates to rerank. DefaultCandidateLimit = 100 // DefaultResultLimit is the default number of results to return after reranking. DefaultResultLimit = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIConfig ¶
type APIConfig struct {
BaseURL string
APIKey string
Model string
Alpha float64
Timeout time.Duration
BatchSize int // Max documents per API call (default: 32)
}
APIConfig holds configuration for the API-based reranker.
func DefaultAPIConfig ¶
func DefaultAPIConfig() APIConfig
DefaultAPIConfig returns sensible defaults for the API reranker.
type APIService ¶
type APIService struct {
// contains filtered or unexported fields
}
APIService provides cross-encoder reranking via an external API (Cohere-compatible).
func NewAPIService ¶
func NewAPIService(cfg APIConfig) (*APIService, error)
NewAPIService creates a new API-based reranker.
func (*APIService) Close ¶
func (s *APIService) Close() error
Close releases resources. API service has no persistent resources to release.
func (*APIService) Rerank ¶
func (s *APIService) Rerank(query string, candidates []Candidate, limit int) ([]RerankResult, error)
Rerank reranks candidates using combined bi-encoder + cross-encoder scores.
func (*APIService) RerankByScore ¶
func (s *APIService) RerankByScore(query string, candidates []Candidate, limit int) ([]RerankResult, error)
RerankByScore reranks candidates sorted by pure cross-encoder score only.
type Candidate ¶
type Candidate struct {
Metadata map[string]any
RerankInfo map[string]float64
ID string
Content string
Score float64
}
Candidate represents a search result candidate for reranking.
type RerankResult ¶
type RerankResult struct {
Metadata map[string]any
ID string
Content string
OriginalScore float64
RerankScore float64
CombinedScore float64
OriginalRank int
RerankRank int
RankImprovement int
}
RerankResult represents a reranked search result.
type Reranker ¶
type Reranker interface {
// Rerank reranks candidates using combined bi-encoder + cross-encoder scores.
// Returns up to limit results sorted by combined score.
Rerank(query string, candidates []Candidate, limit int) ([]RerankResult, error)
// RerankByScore reranks candidates sorted by pure cross-encoder score only.
RerankByScore(query string, candidates []Candidate, limit int) ([]RerankResult, error)
// Score scores a single query-document pair.
// Returns raw cross-encoder logit and normalized (0-1) score.
Score(query, document string) (rawScore, normalizedScore float64, err error)
// Close releases model resources.
Close() error
}
Reranker defines the interface for cross-encoder reranking implementations. Implementations include the API-based APIService.