Documentation
¶
Overview ¶
Package openaiembeddings implements the embedding shape OpenAI defined and every compatible gateway copied: POST {base}/embeddings with {model, input} answering {data: [{embedding, index}]}.
The vendors that speak it disagree about everything optional, so nothing optional is sent unless api.EmbeddingsSettings says the vendor documents it:
- `dimensions` does not exist on NVIDIA NIM or Volcengine's text endpoint;
- `encoding_format` is absent from Zhipu's reference;
- the parameter that separates a search query from an indexed document is `input_type` on NIM, `task` on Jina and `taskType` on Gemini, and most vendors have none;
- images have no standard place: Jina and SGLang take an object in `input`, vLLM takes a chat conversation in `messages`.
This package contains no vendor names.
Index ¶
- type Client
- func (c *Client) AcceptsImages() bool
- func (c *Client) BuildImageMessageBody(img api.EmbedImage, kind api.EmbedInputType) map[string]any
- func (c *Client) BuildImageRequestBody(images []api.EmbedImage, kind api.EmbedInputType) map[string]any
- func (c *Client) BuildRequestBody(texts []string, kind api.EmbedInputType) map[string]any
- func (c *Client) BuildTextMessageBody(text string, kind api.EmbedInputType) map[string]any
- func (c *Client) Embed(ctx context.Context, texts []string, kind api.EmbedInputType) ([][]float32, error)
- func (c *Client) EmbedImages(ctx context.Context, images []api.EmbedImage, kind api.EmbedInputType) ([][]float32, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks the OpenAI embedding shape to one endpoint.
func (*Client) AcceptsImages ¶
AcceptsImages reports whether the vendor declares an image format. Without one a plain OpenAI-compatible server would read image objects as malformed text input.
func (*Client) BuildImageMessageBody ¶
func (c *Client) BuildImageMessageBody(img api.EmbedImage, kind api.EmbedInputType) map[string]any
BuildImageMessageBody is the golden-test entry point for the messages format: one user turn carrying the image, then the configured prompt, as in vLLM's multimodal embedding example.
func (*Client) BuildImageRequestBody ¶
func (c *Client) BuildImageRequestBody(images []api.EmbedImage, kind api.EmbedInputType) map[string]any
BuildImageRequestBody is the golden-test entry point for images. The shape has no standard image input; a vendor that extends it names the key of the object that carries one, and Jina's reference gives {"image": URL or data URI}.
func (*Client) BuildRequestBody ¶
BuildRequestBody is the golden-test entry point: it returns the exact JSON object that would be sent.
func (*Client) BuildTextMessageBody ¶
BuildTextMessageBody is the golden-test entry point for a text sent in the messages format.
func (*Client) Embed ¶
func (c *Client) Embed( ctx context.Context, texts []string, kind api.EmbedInputType, ) ([][]float32, error)
Embed vectorizes one batch, in the order it was given.
func (*Client) EmbedImages ¶
func (c *Client) EmbedImages( ctx context.Context, images []api.EmbedImage, kind api.EmbedInputType, ) ([][]float32, error)
EmbedImages vectorizes one batch of images, in the order it was given.
type Config ¶
type Config struct {
Endpoint api.Endpoint
Settings api.EmbeddingsSettings
// Dimensions is the width the row asked for; it is sent only when the
// vendor names a field for it.
Dimensions int
Retry api.RetryPolicy
}
Config is everything the client needs, already resolved by the api.