Documentation
¶
Overview ¶
Package googleembeddings implements Gemini's batchEmbedContents: one POST carrying a request per text, answering embeddings[].values in order.
Three facts shape it. The per-request `model` must be the fully qualified `models/{id}`, not the bare id the URL already carries. The per-request options — `taskType`, `outputDimensionality` — belong inside `embedContentConfig`; the reference marks the same names at the top level of the request "Deprecated: Please use EmbedContentConfig…". And `taskType` exists on gemini-embedding-001 but not on gemini-embedding-2, which takes its task instruction in the prompt instead — so the field is declared per model rather than for the vendor.
Each text is its own request with a single part: gemini-embedding-2 fuses the parts of one Content into one vector.
Index ¶
- type Client
- func (c *Client) AcceptsImages() bool
- 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) 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 batchEmbedContents to one endpoint.
func (*Client) AcceptsImages ¶
AcceptsImages is always true: inlineData is part of the schema.
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: an image is an inlineData part carrying its MIME type and base64 bytes.
func (*Client) BuildRequestBody ¶
BuildRequestBody is the golden-test entry point.
func (*Client) Embed ¶
func (c *Client) Embed( ctx context.Context, texts []string, kind api.EmbedInputType, ) ([][]float32, error)
Embed vectorizes one batch. The reply carries no index: embeddings come back positionally, one per request, so a short reply is an error rather than a partially filled result.
func (*Client) EmbedImages ¶
func (c *Client) EmbedImages( ctx context.Context, images []api.EmbedImage, kind api.EmbedInputType, ) ([][]float32, error)
EmbedImages vectorizes one batch of images, each its own vector.
type Config ¶
type Config struct {
Endpoint api.Endpoint
Settings api.EmbeddingsSettings
Dimensions int
Retry api.RetryPolicy
}
Config is everything the client needs, already resolved by the api.