Documentation
¶
Overview ¶
Package providerbatch owns request partitioning for provider APIs that bound a request by an input count and by an aggregate token budget.
Text is counted in UTF-8 bytes, which is a conservative upper bound on the number of text tokens: a provider tokenizer never yields more tokens than the input has bytes. A zero limit means the provider documents no such bound, so that limit never splits a request.
The package also owns the one record of provider-reported token usage for a completed request, which the embedding and rerank providers share.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForBatches ¶
func ForBatches(ctx context.Context, operation string, count, maxInputs, maxTokens int, tokens func(int) int, send func(int, int) error) error
ForBatches splits count inputs into consecutive requests and sends each one exactly once, in order.
maxInputs bounds the inputs in one request and maxTokens bounds the request's aggregate cost as reported by tokens; both values are the provider's own documented ceilings. An input that is larger than maxTokens on its own is still sent alone: the provider's own refusal stays visible instead of being hidden or pre-empted here, and no input text is shortened.
A failing send stops the sequence and its error is returned with the failed input range, so a caller that must fail as a whole cannot mistake earlier successes for a result.
func RecordUsage ¶
RecordUsage reports the token accounting a provider returned for one request it completed: one record per completed request, so billable work is neither lost nor multiplied by the inputs a request carried and never replaced by a locally computed estimate.
operation names what the request did ("embedding", "rerank"); inputs is the number of inputs that request carried. A caller records usage as soon as the provider response exists, before deciding whether its payload is usable, so a response later rejected as unusable still reports the tokens it cost.
Types ¶
This section is empty.