Documentation
¶
Index ¶
- Constants
- type CohereEmbeddingFunction
- func (c *CohereEmbeddingFunction) CreateEmbedding(ctx context.Context, req *CreateEmbeddingRequest) (*CreateEmbeddingResponse, error)
- func (c *CohereEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]embeddings.Embedding, error)
- func (c *CohereEmbeddingFunction) EmbedQuery(ctx context.Context, document string) (embeddings.Embedding, error)
- type CreateEmbeddingRequest
- type CreateEmbeddingResponse
- type EmbeddingType
- type EmbeddingsResponse
- type InputType
- type Option
- func WithAPIKey(apiKey string) Option
- func WithAPIVersion(apiVersion ccommons.APIVersion) Option
- func WithBaseURL(baseURL string) Option
- func WithDefaultModel(model embeddings.EmbeddingModel) Option
- func WithEmbeddingTypes(embeddingTypes ...EmbeddingType) Option
- func WithEnvAPIKey() Option
- func WithModel(model embeddings.EmbeddingModel) Option
- func WithRetryStrategy(retryStrategy httpc.RetryStrategy) Option
- func WithTruncateMode(truncate TruncateMode) Option
- type TruncateMode
Constants ¶
const ( ModelEmbedEnglishV20 embeddings.EmbeddingModel = "embed-english-v2.0" ModelEmbedEnglishV30 embeddings.EmbeddingModel = "embed-english-v3.0" ModelEmbedMultilingualV20 embeddings.EmbeddingModel = "embed-multilingual-v2.0" ModelEmbedMultilingualV30 embeddings.EmbeddingModel = "embed-multilingual-v3.0" ModelEmbedEnglishLightV20 embeddings.EmbeddingModel = "embed-english-light-v2.0" ModelEmbedEnglishLightV30 embeddings.EmbeddingModel = "embed-english-light-v3.0" DefaultEmbedModel embeddings.EmbeddingModel = ModelEmbedEnglishV20 )
const (
DefaultEmbedEndpoint = "embed"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CohereEmbeddingFunction ¶
type CohereEmbeddingFunction struct {
ccommons.CohereClient
DefaultTruncateMode TruncateMode
DefaultEmbeddingTypes []EmbeddingType
DefaultInputType InputType
EmbeddingEndpoint string
}
func NewCohereEmbeddingFunction ¶
func NewCohereEmbeddingFunction(opts ...Option) (*CohereEmbeddingFunction, error)
func (*CohereEmbeddingFunction) CreateEmbedding ¶
func (c *CohereEmbeddingFunction) CreateEmbedding(ctx context.Context, req *CreateEmbeddingRequest) (*CreateEmbeddingResponse, error)
func (*CohereEmbeddingFunction) EmbedDocuments ¶
func (c *CohereEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]embeddings.Embedding, error)
EmbedDocuments embeds the given documents and returns the embeddings. Accepts value model in context to override the default model. Accepts value embedding_types in context to override the default embedding types.
func (*CohereEmbeddingFunction) EmbedQuery ¶
func (c *CohereEmbeddingFunction) EmbedQuery(ctx context.Context, document string) (embeddings.Embedding, error)
EmbedQuery embeds the given query and returns the embedding. Accepts value model in context to override the default model. Accepts value embedding_types in context to override the default embedding types.
type CreateEmbeddingRequest ¶
type CreateEmbeddingRequest struct {
Model string `json:"model"`
Texts []string `json:"texts"`
Truncate TruncateMode `json:"truncate,omitempty"`
EmbeddingTypes []EmbeddingType `json:"embedding_types,omitempty"`
InputType InputType `json:"input_type,omitempty"`
}
func (*CreateEmbeddingRequest) JSON ¶
func (c *CreateEmbeddingRequest) JSON() (string, error)
type CreateEmbeddingResponse ¶
type CreateEmbeddingResponse struct {
ID string `json:"id"`
Texts []string `json:"texts"`
Embeddings *EmbeddingsResponse `json:"embeddings"`
Meta map[string]any `json:"meta"`
}
type EmbeddingType ¶
type EmbeddingType string
const ( EmbeddingTypeFloat32 EmbeddingType = "float" EmbeddingTypeInt8 EmbeddingType = "int8" EmbeddingTypeUInt8 EmbeddingType = "uint8" EmbeddingTypeBinary EmbeddingType = "binary" EmbeddingTypeUBinary EmbeddingType = "ubinary" )
type EmbeddingsResponse ¶
type EmbeddingsResponse struct {
Float32 [][]float32 `json:"float,omitempty"`
Int8 [][]int8 `json:"int8,omitempty"`
UInt8 [][]uint8 `json:"uint8,omitempty"`
}
func (*EmbeddingsResponse) UnmarshalJSON ¶
func (e *EmbeddingsResponse) UnmarshalJSON(b []byte) error
type Option ¶
type Option func(p *CohereEmbeddingFunction) ccommons.Option
func WithAPIKey ¶
func WithAPIVersion ¶
func WithAPIVersion(apiVersion ccommons.APIVersion) Option
func WithBaseURL ¶
WithBaseURL sets the base URL for the Cohere API - the default is https://api.cohere.ai
func WithDefaultModel ¶
func WithDefaultModel(model embeddings.EmbeddingModel) Option
WithDefaultModel sets the default model for the Cohere. This can be overridden in the context of EF embed call. Available models: embed-english-v3.0 1024 embed-multilingual-v3.0 1024 embed-english-light-v3.0 384 embed-multilingual-light-v3.0 384 embed-english-v2.0 4096 (default) embed-english-light-v2.0 1024 embed-multilingual-v2.0 768
func WithEmbeddingTypes ¶
func WithEmbeddingTypes(embeddingTypes ...EmbeddingType) Option
WithEmbeddingTypes sets the default embedding types for the Cohere API - Available types: float (default) int8 uint8 binary ubinary TODO we do not have support for returning multiple embedding types from the EmbeddingFunction, so for float->int8, unit8 are supported and returned in the that order
func WithEnvAPIKey ¶
func WithEnvAPIKey() Option
WithEnvAPIKey configures the client to use the COHERE_API_KEY environment variable as the API key
func WithModel ¶
func WithModel(model embeddings.EmbeddingModel) Option
WithModel sets the default model for the Cohere API - Available models: embed-english-v3.0 1024 embed-multilingual-v3.0 1024 embed-english-light-v3.0 384 embed-multilingual-light-v3.0 384 embed-english-v2.0 4096 (default) embed-english-light-v2.0 1024 embed-multilingual-v2.0 768
func WithRetryStrategy ¶
func WithRetryStrategy(retryStrategy httpc.RetryStrategy) Option
WithRetryStrategy configures the client to use the specified retry strategy
func WithTruncateMode ¶
func WithTruncateMode(truncate TruncateMode) Option
WithTruncateMode sets the default truncate mode for the Cohere API - Available modes: NONE START END (default)
type TruncateMode ¶
type TruncateMode string
const ( NONE TruncateMode = "NONE" START TruncateMode = "START" END TruncateMode = "END" )