Embedding a batch of text
Embeddings turn text into vectors, which is how retrieval and similarity search get their numbers. One Embed call
sends the whole input slice and returns one vector per input in the same order.
Creating an embedder
The OpenAI-compatible adapter builds an embedder from the same endpoint settings as its Generator.
embedder, err := openai.NewEmbedder(openai.EndpointConfig{
APIKey: os.Getenv("GOLATO_API_KEY"),
BaseURL: os.Getenv("GOLATO_BASE_URL"),
})
if err != nil {
return err
}
Sending a batch
A request needs a non-blank, valid UTF-8 model name, a non-empty input slice, and valid UTF-8 in every input string. The
example reads the model from GOLATO_EMBEDDING_MODEL, which is an application convention like the other GOLATO_
names.
model := os.Getenv("GOLATO_EMBEDDING_MODEL")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
response, err := embedder.Embed(ctx, embedding.Request{
Model: model,
Inputs: []string{"first document", "second document"},
})
if err != nil {
return err
}
for index, vector := range response.Vectors {
fmt.Printf("input %d: %d dimensions\n", index, len(vector))
}
A successful response has exactly one non-empty vector per input, and every vector has the same dimension. Indexed provider items are checked for a complete, unique index set before Golato returns the vectors in input order.
Deciding how to use the vectors
Golato returns raw [][]float64 values. It does not store, split, search, rank, or retry them. If the provider limits
batch size, the application splits the input itself, and it decides where and how to persist the result.
Handling failures
A successful response body is limited to 16 MiB. A malformed or oversized successful body, including
io.ErrUnexpectedEOF while reading it, matches provider.ErrInvalidResponse. Other read failures from a successful
response are a *provider.TransportError with the read phase, and a failed connection uses the establish phase. A
non-success HTTP response stays an *provider.HTTPStatusError, including when reading its error body fails, with that
read error available as Cause. Caller cancellation and deadlines keep their standard context identity.
Configuring the OpenAI-compatible adapter lists the complete error table.