curl -s 'https://www.unum.cloud/docs/uform/go/encoding.md' | claude -p "How would this fit my code?"
One verb per input form, each spelled as in C, and each taking its inputs, the EncodeOutputs to keep, the scalar every output lands as, the arena, and last a config, nil for none:
TextEncode(texts, ..) takes UTF-8 texts, a byte per token, since models are tokenizer-free.
ImageEncode(files, ..) takes JPEG, PNG or WebP files.
ImageEncodePixels(pixels, heights, widths, ..) takes interleaved 8-bit RGB, heights[i] rows of widths[i] pixels per item.
VideoEncode(files, ..) takes MP4 or WebM clips.
AudioEncode(files, ..) takes WAV, FLAC, MP3 or Opus recordings.
A Tape passes the elements and count + 1 offsets to the library without a copy: BytesTape(data, offsets) for texts and files, and SamplesTape(data, offsets) for recordings. TapeOf(items) gathers separate strings or byte slices into a fresh tape with one copy, and SamplesOf(recordings) does so for samples:
tape := uform.BytesTape([]byte("first documentthe second"), []uint{0, 14, 24})encoded, err := model.TextEncode(tape, uform.EncodeOutputsStates, uform.ScalarBF16, arena, nil)offsets := encoded.States.Offsets() // item `i` spans rows `offsets[i]` up to `offsets[i + 1]`second, err := encoded.States.Item(1) // the rows of one item, as `Rows`
EncodeOutputsEmbeddings, EncodeOutputsStates and EncodeOutputsTokenVectors join with |, and a surface left out answers a zero Count and costs nothing past the final norm.
Token vectors are the token head’s unit rows, one per state, which late-interaction rerankers score; a model without the head answers StatusUnsupported.
The config reaches the knobs:
Rows reports its Count, Columns, Stride and Scalar, and uform.RowValues[float32](rows, i) views one row’s values, refused with StatusInvalidArgument when the rows hold another scalar type. RowsTape adds the Offsets and an Item per input.
A handler answering false stops the call, which fails with StatusCancelled and publishes nothing.
API
Types
AudioEncodeConfigAudioEncodeConfig holds the knobs of AudioEncode and AudioEncodeSamples; nil derives every field.
EncodeOutputsEncodeOutputs names the surfaces an encode verb keeps from its one forward, after the C fields they fill; | joins them, and a surface left out costs nothing past the final norm.
EncodeOutputsEmbeddings keeps one pooled embedding per item, past the attention pool and the projection head.
EncodeOutputsStates
EncodeOutputsStates keeps one final-norm state per token left after truncation.
EncodeOutputsTokenVectors
EncodeOutputsTokenVectors keeps one unit vector of the token head per token left after truncation; a model without the head fails the call with StatusUnsupported.
EncodedEncoded is what an encode verb wrote into the arena it was given: the surfaces its EncodeOutputs named, each with a zero Count when left out, and none normalized.
type VideoEncodeStats struct {
Truncated uint
Tokens uint
}
Mirrors uform_video_encode_stats_t.
Fields
Truncated
uint
Truncated counts the items cut at the model's context in tubes.
Tokens
uint
Tokens counts the tubes the call encoded, after truncation.
StructRowsRows is a run of rows a call wrote packed into its arena, one per item, readable until the arena serves another call, after which RowValues fails with StatusContended.4
StructRowsTapeRowsTape is a ragged run of rows a call wrote into its arena, item i spanning the rows between two consecutive RowsTape.Offsets, readable until the arena serves another call.3
It panics with StatusContended once a later call took the arena, as a slice bound does, and the slice is valid only until then.
EnumScalarScalar names a computed or exchanged scalar type by width and encoding, numbered as USearch numbers it, so a run of embeddings is a run USearch indexes without conversion.2
StructTapeTape views a ragged batch as Apache Arrow lays one out: elements end to end, and one more offset than entries around them, entry i spanning offsets[i] up to offsets[i+1].6
StructTapeViewTapeView is a ragged batch a call wrote into its arena, readable until the arena serves another call: one probability per choice, item by item, for TextChoose.2
RowValuesRowValues views one row's values in the arena, refused with StatusInvalidArgument when Value is not the scalar type they were written as or row is not below Count, and with StatusContended once a later call took the arena.
TapeEntryTapeEntry views one entry's elements in the arena, refused with StatusInvalidArgument when Value is not the scalar type they were written as or entry is not below Entries.