cohere

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CohereModel

type CohereModel = ccommons.CohereModel
const (
	DefaultRerankingEndpoint               = "rerank"
	ModelRerankEnglishV30      CohereModel = "rerank-english-v3.0"
	DefaultModel               CohereModel = ModelRerankEnglishV30
	ModelRerankMultilingualV30 CohereModel = "rerank-multilingual-v3.0"
	ModelRerankEnglishV20      CohereModel = "rerank-english-v2.0"
	ModelRerankMultilingualV20 CohereModel = "rerank-multilingual-v2.0"
)

type CohereRerankingFunction

type CohereRerankingFunction struct {
	ccommons.CohereClient
	TopN            int
	RerankFields    []string
	ReturnDocuments bool
	MaxChunksPerDoc int
	RerankEndpoint  string
}

func NewCohereRerankingFunction

func NewCohereRerankingFunction(opts ...Option) (*CohereRerankingFunction, error)

func (CohereRerankingFunction) ID

ID returns the of the reranking function. We use `cohere-` prefix with the default model

func (CohereRerankingFunction) Rerank

func (CohereRerankingFunction) RerankResults

type Option

type Option func(p *CohereRerankingFunction) ccommons.Option

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDefaultModel

func WithDefaultModel(model ccommons.CohereModel) Option

func WithEnvAPIKey

func WithEnvAPIKey() Option

WithEnvAPIKey configures the client to use the COHERE_API_KEY environment variable as the API key

func WithMaxChunksPerDoc

func WithMaxChunksPerDoc(maxChunks int) Option

func WithRerankFields

func WithRerankFields(fields []string) Option

WithRerankFields configures the client to use the specified fields for reranking if the documents are in JSON format

func WithRetryStrategy

func WithRetryStrategy(retryStrategy httpc.RetryStrategy) Option

WithRetryStrategy configures the client to use the specified retry strategy

func WithReturnDocuments

func WithReturnDocuments() Option

WithReturnDocuments configures the client to return the original documents in the response

func WithTopN

func WithTopN(topN int) Option

type RerankRequest

type RerankRequest struct {
	Model           string   `json:"model"`
	Query           string   `json:"query"`
	Documents       []any    `json:"documents"`
	TopN            int      `json:"top_n,omitempty"`
	RerankFields    []string `json:"rerank_fields,omitempty"`
	ReturnDocuments bool     `json:"return_documents,omitempty"`
	MaxChunksPerDoc int      `json:"max_chunks_per_doc,omitempty"`
}

type RerankResponse

type RerankResponse struct {
	ID      string         `json:"id"`
	Results []RerankResult `json:"results"`
	Meta    map[string]any `json:"meta"`
}

type RerankResult

type RerankResult struct {
	Document struct {
		Text string `json:"text"`
	} `json:"document"`
	RelevanceScore float32 `json:"relevance_score"`
	Index          int     `json:"index"`
}

Jump to

Keyboard shortcuts

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