Documentation
¶
Index ¶
- Constants
- Variables
- func AsFloat32(data []float64) []float32
- func AsFloat64(data []float32) []float64
- func EmbedderSchemes() []string
- func RegisterEmbedder[T Float](ctx context.Context, scheme string, init_func EmbedderInitializationFunc[T]) error
- type CommonEmbeddingsResponse
- func (r *CommonEmbeddingsResponse[T]) Created() int64
- func (r *CommonEmbeddingsResponse[T]) Dimensions() int32
- func (r *CommonEmbeddingsResponse[T]) Embeddings() []T
- func (r *CommonEmbeddingsResponse[T]) Id() string
- func (r *CommonEmbeddingsResponse[T]) Model() string
- func (r *CommonEmbeddingsResponse[T]) Precision() string
- type Embedder
- func NewEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewEmbedder32(ctx context.Context, uri string) (Embedder[float32], error)
- func NewEmbedder64(ctx context.Context, uri string) (Embedder[float64], error)
- func NewEncoderfileEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewLlamafileEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewMLXClipEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewMLXClipLocalClientEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewMobileCLIPEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewNullEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewOllamaEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewOpenCLIPEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewRouteEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewSigLIPCommandLineEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewSigLIPLocalClientEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- func NewYzmaEmbedder[T Float](ctx context.Context, uri string) (Embedder[T], error)
- type EmbedderInitializationFunc
- type EmbeddingsRequest
- type EmbeddingsResponse
- type EncoderfileEmbedder
- type Float
- type LlamafileEmbedder
- type LocalClient
- type LocalClientEmbeddingRequest
- type LocalClientEmbeddingResponse
- type LocalClientImageDataEmbeddingRequest
- type MLXClipEmbedder
- type MLXClipEmbeddingsResponse
- type MLXClipLocalClientEmbedder
- func (e *MLXClipLocalClientEmbedder[T]) Close() error
- func (e *MLXClipLocalClientEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
- func (e *MLXClipLocalClientEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
- type MobileCLIPEmbedder
- type NullEmbedder
- type OllamaEmbedder
- type OpenCLIPEmbedder
- type RouteEmbedder
- type SigLIPCommandLineEmbedder
- func (e *SigLIPCommandLineEmbedder[T]) Close() error
- func (e *SigLIPCommandLineEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
- func (e *SigLIPCommandLineEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
- type SigLIPLocalClientEmbedder
- type YzmaEmbedder
Constants ¶
const ROUTE_SEPARATOR string = "..."
ROUTE_SEPARATOR is the token that separates the client URI from the list of model names in the `client-uri` query parameter. It is defined here to make it easy to change the separator without touching every place in the code that uses it.
Variables ¶
var NotImplemented = errors.New("Not implemented")
Functions ¶
func EmbedderSchemes ¶
func EmbedderSchemes() []string
Schemes returns the list of schemes that have been registered.
func RegisterEmbedder ¶
func RegisterEmbedder[T Float](ctx context.Context, scheme string, init_func EmbedderInitializationFunc[T]) error
RegisterEmbedder registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Embedder` instances by the `NewEmbedder` method.
Types ¶
type CommonEmbeddingsResponse ¶ added in v0.1.0
type CommonEmbeddingsResponse[T Float] struct { EmbeddingsResponse[T] `json:",omitempty"` CommonId string `json:"id,omitempty"` CommonEmbeddings []T `json:"embeddings"` CommonModel string `json:"model"` CommonCreated int64 `json:"created"` CommonPrecision string `json:"precision"` }
func (*CommonEmbeddingsResponse[T]) Created ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Created() int64
func (*CommonEmbeddingsResponse[T]) Dimensions ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Dimensions() int32
func (*CommonEmbeddingsResponse[T]) Embeddings ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Embeddings() []T
func (*CommonEmbeddingsResponse[T]) Id ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Id() string
func (*CommonEmbeddingsResponse[T]) Model ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Model() string
func (*CommonEmbeddingsResponse[T]) Precision ¶ added in v0.1.0
func (r *CommonEmbeddingsResponse[T]) Precision() string
type Embedder ¶
type Embedder[T Float] interface { TextEmbeddings(context.Context, *EmbeddingsRequest) (EmbeddingsResponse[T], error) ImageEmbeddings(context.Context, *EmbeddingsRequest) (EmbeddingsResponse[T], error) Close() error }
Embedder defines an interface for generating (vector) embeddings
func NewEmbedder ¶
newEmbedder returns a new `Embedder` instance configured by 'uri'. The value of 'uri' is parsed as a `url.URL` and its scheme is used as the key for a corresponding `EmbedderInitializationFunc` function used to instantiate the new `Embedder`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterEmbedder` method.
func NewEmbedder32 ¶ added in v0.1.0
func NewEmbedder64 ¶ added in v0.1.0
func NewEncoderfileEmbedder ¶ added in v0.1.0
func NewLlamafileEmbedder ¶ added in v0.1.0
func NewMLXClipEmbedder ¶ added in v0.1.0
func NewMLXClipLocalClientEmbedder ¶ added in v0.4.0
func NewMobileCLIPEmbedder ¶ added in v0.1.0
func NewNullEmbedder ¶
func NewOllamaEmbedder ¶ added in v0.1.0
func NewOpenCLIPEmbedder ¶ added in v0.1.0
func NewRouteEmbedder ¶ added in v0.5.0
NewRouteEmbedder creates a new RouteEmbedder from the supplied URI. The URI must be in the form:
route://?client-uri=CLIENT_URI…MODEL…MODEL
The client URI may be repeated to register multiple clients. Each client URI is passed to NewEmbedder64 or NewEmbedder32 depending on the precision requested by the scheme suffix.
func NewSigLIPCommandLineEmbedder ¶ added in v0.3.0
func NewSigLIPLocalClientEmbedder ¶ added in v0.3.0
func NewYzmaEmbedder ¶ added in v0.6.0
NewYzmaEmbedder creates a new YzmaEmbedder based on the provided URI.
The URI may include query parameters that configure the embedder. The function downloads the yzma binary if it is not already present and ensures that the model root directory exists. It returns an error if the URI is malformed, the binary cannot be downloaded, or the configuration parameters are invalid. YzmaEmbedder is instantiated by 'uri' which is expected to take the form of: The URI may contain query parameters that configure the embedder. The supported parameters are:
yzma://{PATH_TO_YZMA_LIB}?{QUERY_PARAMETERS)
Where `{PATH_TO_YZMA}` is the path the yzma-specific llama.cpp build. If empty then the code will check for a `YZMA_LIB` environment variable. If the path remains empty then a temporary directory will be created and an device-specific build will be downloaded. Valid query parameters are:
- **context-size** – Maximum number of tokens in a llama context. If omitted, the default of 0 (use library default) is used.
- **batch-size** – Maximum number of tokens processed per batch. If omitted, the default of 0 (use library default) is used.
- **pooling** – Pooling strategy used to aggregate token embeddings. Accepted values are the same strings that the `llama.PoolingType` type understands (e.g. `"mean"`, `"sum"`). The default is `"mean"`.
- **processor** – Target CPU instruction set for the downloaded yzma binary (e.g. `avx`, `neon`). If omitted, the library will automatically select an appropriate processor.
- **version** – The yzma release version to download. The default is `"v0.3.0"`. The value should be a full git tag (e.g. `v0.3.0`), not an empty string.
- **model-root** – Directory where the llama model files are stored. If omitted, a subdirectory `models` of the library root (`lib_path`) is used.
type EmbedderInitializationFunc ¶
EmbedderInitializationFunc is a function defined by individual embedder package and used to create an instance of that embedder
type EmbeddingsRequest ¶ added in v0.1.0
type EmbeddingsResponse ¶ added in v0.1.0
type EncoderfileEmbedder ¶ added in v0.1.0
EncoderfileEmbedder implements the `Embedder` interface using an Encoderfile API endpoint to derive embeddings.
func (*EncoderfileEmbedder[T]) ImageEmbeddings ¶ added in v0.1.0
func (e *EncoderfileEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*EncoderfileEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *EncoderfileEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type LlamafileEmbedder ¶ added in v0.1.0
LlamafileEmbedder implements the `Embedder` interface using an Llamafile API endpoint to derive embeddings.
func (*LlamafileEmbedder[T]) Close ¶ added in v0.6.0
func (e *LlamafileEmbedder[T]) Close() error
func (*LlamafileEmbedder[T]) ImageEmbeddings ¶ added in v0.1.0
func (e *LlamafileEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*LlamafileEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *LlamafileEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type LocalClient ¶ added in v0.3.0
type LocalClient struct {
// contains filtered or unexported fields
}
func NewLocalClient ¶ added in v0.3.0
func NewLocalClient(ctx context.Context, uri string) (*LocalClient, error)
type LocalClientEmbeddingRequest ¶ added in v0.3.0
type LocalClientEmbeddingRequest struct {
Content string `json:"content,omitempty"`
ImageData []*LocalClientImageDataEmbeddingRequest `json:"image_data,omitempty"`
}
type LocalClientEmbeddingResponse ¶ added in v0.3.0
type LocalClientImageDataEmbeddingRequest ¶ added in v0.3.0
type MLXClipEmbedder ¶ added in v0.1.0
func (*MLXClipEmbedder[T]) ImageEmbeddings ¶ added in v0.1.1
func (e *MLXClipEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*MLXClipEmbedder[T]) TextEmbeddings ¶ added in v0.1.1
func (e *MLXClipEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type MLXClipEmbeddingsResponse ¶ added in v0.4.0
type MLXClipLocalClientEmbedder ¶ added in v0.4.0
type MLXClipLocalClientEmbedder[T Float] struct { Embedder[T] // contains filtered or unexported fields }
func (*MLXClipLocalClientEmbedder[T]) Close ¶ added in v0.6.0
func (e *MLXClipLocalClientEmbedder[T]) Close() error
func (*MLXClipLocalClientEmbedder[T]) ImageEmbeddings ¶ added in v0.4.0
func (e *MLXClipLocalClientEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*MLXClipLocalClientEmbedder[T]) TextEmbeddings ¶ added in v0.4.0
func (e *MLXClipLocalClientEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type MobileCLIPEmbedder ¶ added in v0.1.0
MobileCLIPEmbedder implements the `Embedder` interface using an MobileCLIP API endpoint to derive embeddings.
func (*MobileCLIPEmbedder[T]) Close ¶ added in v0.6.0
func (e *MobileCLIPEmbedder[T]) Close() error
func (*MobileCLIPEmbedder[T]) ImageEmbeddings ¶ added in v0.1.0
func (e *MobileCLIPEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*MobileCLIPEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *MobileCLIPEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type NullEmbedder ¶
NullEmbedder implements the `Embedder` interface using an Null API endpoint to derive embeddings.
func (*NullEmbedder[T]) Close ¶ added in v0.6.0
func (e *NullEmbedder[T]) Close() error
func (*NullEmbedder[T]) ImageEmbeddings ¶
func (e *NullEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*NullEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *NullEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type OllamaEmbedder ¶ added in v0.1.0
OllamaEmbedder implements the `Embedder` interface using an Ollama API endpoint to derive embeddings.
func (*OllamaEmbedder[T]) Close ¶ added in v0.6.0
func (e *OllamaEmbedder[T]) Close() error
func (*OllamaEmbedder[T]) ImageEmbeddings ¶ added in v0.1.0
func (e *OllamaEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*OllamaEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *OllamaEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type OpenCLIPEmbedder ¶ added in v0.1.0
OpenCLIPEmbedder implements the `Embedder` interface using an OpenCLIP API endpoint to derive embeddings.
func (*OpenCLIPEmbedder[T]) Close ¶ added in v0.6.0
func (e *OpenCLIPEmbedder[T]) Close() error
func (*OpenCLIPEmbedder[T]) ImageEmbeddings ¶ added in v0.1.0
func (e *OpenCLIPEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*OpenCLIPEmbedder[T]) TextEmbeddings ¶ added in v0.1.0
func (e *OpenCLIPEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type RouteEmbedder ¶ added in v0.5.0
RouteEmbedder implements the Embedder interface by routing requests to different underlying clients depending on the requested model. The generic type parameter T must satisfy the Float constraint defined in another file of this package.
The struct embeds an Embedder[T] interface to satisfy the interface but the methods below provide the actual routing logic.
func (*RouteEmbedder[T]) ImageEmbeddings ¶ added in v0.5.0
func (e *RouteEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
ImageEmbeddings implements the Embedder interface. It forwards the request to the underlying client that matches the requested model.
func (*RouteEmbedder[T]) TextEmbeddings ¶ added in v0.5.0
func (e *RouteEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
TextEmbeddings implements the Embedder interface. It forwards the request to the underlying client that matches the requested model.
type SigLIPCommandLineEmbedder ¶ added in v0.3.0
type SigLIPCommandLineEmbedder[T Float] struct { Embedder[T] // contains filtered or unexported fields }
func (*SigLIPCommandLineEmbedder[T]) Close ¶ added in v0.6.0
func (e *SigLIPCommandLineEmbedder[T]) Close() error
func (*SigLIPCommandLineEmbedder[T]) ImageEmbeddings ¶ added in v0.3.0
func (e *SigLIPCommandLineEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*SigLIPCommandLineEmbedder[T]) TextEmbeddings ¶ added in v0.3.0
func (e *SigLIPCommandLineEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type SigLIPLocalClientEmbedder ¶ added in v0.3.0
type SigLIPLocalClientEmbedder[T Float] struct { Embedder[T] // contains filtered or unexported fields }
func (*SigLIPLocalClientEmbedder[T]) ImageEmbeddings ¶ added in v0.3.0
func (e *SigLIPLocalClientEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
func (*SigLIPLocalClientEmbedder[T]) TextEmbeddings ¶ added in v0.3.0
func (e *SigLIPLocalClientEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
type YzmaEmbedder ¶ added in v0.6.0
YzmaEmbedder implements the `Embedder` interface using the `hybridgroup/yzma` package to derive embeddings.
func (*YzmaEmbedder[T]) Close ¶ added in v0.6.0
func (e *YzmaEmbedder[T]) Close() error
Close releases resources held by the yzma backend. It also removes any temporary directories that were created for downloading the yzma binary.
func (*YzmaEmbedder[T]) ImageEmbeddings ¶ added in v0.6.0
func (e *YzmaEmbedder[T]) ImageEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
ImageEmbeddings is not implemented for the yzma backend. It returns the `NotImplemented` error to indicate that image embeddings are unsupported.
func (*YzmaEmbedder[T]) TextEmbeddings ¶ added in v0.6.0
func (e *YzmaEmbedder[T]) TextEmbeddings(ctx context.Context, req *EmbeddingsRequest) (EmbeddingsResponse[T], error)
TextEmbeddings derives embeddings for the text contained in the request. It uses the yzma backend to tokenize the input, create a llama context, and retrieve the embedding vector. The vector is normalised to unit length and returned in the `EmbeddingsResponse`. The response includes the model name, the timestamp of creation, and the precision used.