base

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Embedder
	UsageListener
}

func (*Client) CreateEmbedding

func (c *Client) CreateEmbedding(ctx context.Context, data []string) ([][]float32, error)

type ClientOption

type ClientOption func(*Config)

ClientOption mutates Config. Each provider may alias this type so that its constructor accepts a consistent set of generic options alongside any provider-specific ones.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the default endpoint URL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient injects a custom *http.Client* (for timeouts, transport, …).

func WithModel

func WithModel(model string) ClientOption

WithModel sets/overrides the model name.

type Config

type Config struct {
	// BaseURL is the root URL of the remote embedding service (e.g. https://api.openai.com).
	BaseURL string

	// HTTPClient performs the underlying HTTP calls.  When nil the provider
	// should fall back to *http.DefaultClient* or create its own with sensible
	// timeout.
	HTTPClient *http.Client

	// Model identifies the embedding model (e.g. "text-embedding-3-small") to
	// be used by the provider.  The concrete provider may fall back to its own
	// default if Model is left empty.
	Model string
}

Config groups the fields that are common to every embedder provider Client.

Several provider implementations (OpenAI, Ollama, VertexAI, …) were declaring the same set of fields (BaseURL, HTTPClient, Model) independently in their dedicated client structs and duplicating functional-option helpers to mutate them. Config centralises those shared attributes so that every provider can embed *base.Config* and inherit the fields automatically. Generic functional-options defined in this package operate on Config and therefore can be reused by all providers, eliminating the previous boiler-plate.

type Embedder

type Embedder interface {
	Embed(ctx context.Context, data []string) (vector [][]float32, totalTokens int, err error)
}

type UsageListener

type UsageListener func(data []string, tokens int)

Jump to

Keyboard shortcuts

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