Referencia · §8.27

What model calls cost

models, budget, §M14.22 E8

Ez az oldal a nucleus saját dokumentációjából készül, ezért angol nyelvű.

Four more core options of CREATE MODEL, for any provider (positive integers, 22023 otherwise; kept in the model record, version 3): batch_tokens (the most tokens a call sends), requests_per_minute, tokens_per_minute, parallel (calls at once). A call’s texts — those the cache did not answer, each once — are packed in order into batches of at most the provider’s batch and batch_tokens (a text over it goes alone; the provider says whether it takes it). A text’s tokens are estimated as its UTF-8 bytes / 3, rounded up, or counted by the provider (count_tokens) for a model with files when a token limit is set.

The rate limits are two token buckets per database and model in the process, each holding up to a minute’s limit and refilled steadily (a redefined model’s start full); a batch takes a call and its tokens (at most a bucket’s size). Time is the database’s clock, so the simulation passes it. A statement’s call waits for the buckets (Kv::sleep) unless the wait would pass its deadline — then 53400, its hint try again in n ms (the model's rate limit). An embedding column’s round (§8.24) never waits: the jobs get the same 53400, come back after the hint’s wait, and do not count toward the model’s circuit (models::throttled). With parallel > 1, a model without files (a remote one) sends its batches on that many threads, answers kept in order; a local model uses its threads.

Tokens used are the provider’s where it reports them (Request::report_tokens: OpenAI’s and Voyage’s usage.total_tokens, Cohere’s meta.billed_units.input_tokens, the local model’s own token count), else the estimate. Each statement is charged as it calls (budget::ModelCost: calls, texts sent, cache hits, tokens, errors, µs in calls and waiting for limits), its parallel workers too (they share the statement’s counter through parallel::Ambient): EXPLAIN ANALYZE prints a Models: line, nc_catalog.statements sums model_* columns, nc_catalog.models the process’s tokens and throttled_ms. Tests: tests/models.rs (limits_batches_and_costs), tests/embedding_columns.rs (a_rate_limit_spaces_the_rounds), modules/embeddings/tests/providers.rs (usage reported, calls at once).