huggingface

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BaseURL = "https://api-inference.huggingface.co/pipeline/feature-extraction/"
View Source
const (
	DefaultEmbedderModel = "sentence-transformers/all-MiniLM-L6-v2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Errors StringList `json:"error,omitempty"`
}

func (APIError) Error

func (e APIError) Error() string

func (APIError) IsError

func (e APIError) IsError() bool

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is Voyage HTTP API client.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new HTTP API client and returns it. By default it reads the Voyage API key from HUGGING_FACE_API_KEY env var and uses the default Go http.Client for making API requests. You can override the default options via the client methods.

func (*Client) CreateEmbeddings

func (c *Client) CreateEmbeddings(ctx context.Context, req *EmbeddingRequest) ([][]float64, error)

type Embedder

type Embedder struct {
	*Client

	embedder.Options
}

func New

func New(client *Client, opts ...embedder.Option) *Embedder

func (*Embedder) BatchEmbed

func (p *Embedder) BatchEmbed(ctx context.Context, parts []string, usage *components.LLMUsage) ([]embedder.Embedding, error)

func (*Embedder) DotProduct

func (p *Embedder) DotProduct(ctx context.Context, target, query *embedder.Embedding) (float64, error)

DotProduct calculates the dot product of the embedding vector with another embedding vector. Both vectors must have the same length; otherwise, an ErrVectorLengthMismatch is returned. The method returns the calculated dot product as a float32 value.

func (*Embedder) Embed

func (p *Embedder) Embed(ctx context.Context, text string, embedding *embedder.Embedding, usage *components.LLMUsage) error

func (*Embedder) SetClient

func (p *Embedder) SetClient(clt *Client)

type EmbeddingRequest

type EmbeddingRequest struct {
	Inputs  []string `json:"inputs,omitempty"`
	Options options  `json:"options,omitempty"`
	Model   string   `json:"-"`
}

type Option

type Option func(*Options)

Option is functional option.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the HTTP client.

type Options

type Options struct {
	APIKey     string
	BaseURL    string
	HTTPClient *http.Client
}

Options are client options

type StringList

type StringList []string

func (StringList) MarshalJSON

func (s StringList) MarshalJSON() ([]byte, error)

MarshalJSON serializes as a single string if only one element exists, otherwise as a list

func (*StringList) UnmarshalJSON

func (s *StringList) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both single string and list of strings

Jump to

Keyboard shortcuts

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