googleembeddings

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 4 Imported by: 0

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.

https://ai.google.dev/api/embeddings

Index

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 New

func New(cfg Config) *Client

New builds a client.

func (*Client) AcceptsImages

func (c *Client) AcceptsImages() bool

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

func (c *Client) BuildRequestBody(texts []string, kind api.EmbedInputType) map[string]any

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.

Jump to

Keyboard shortcuts

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