1. Model Configuration
Models are stored in a table with the following structure:max_batch_size
max_batch_size sets the maximum number of input tuples Flock groups into a single provider request. Each request counts as one call against rate_limit and provider quotas.
Default: 16.
max_batch_size inline when calling a function:
Token-limit retries
If a batch exceeds the model context window, Flock automatically retries with smaller batches instead of failing the whole query. Scalar functions (llm_complete, llm_filter, llm_embedding):
- Flock starts from
min(max_batch_size, row_count). - On a context-window / token-limit error, the failed batch is retried at half the size:
64 → 32 → 16 → … - After a successful batch, the next chunk starts again at the configured
max_batch_size. - If a batch cannot be reduced further (
batch_sizeof 1 still fails), affected rows returnNULL.
is_async: false) retries batches sequentially. Async (is_async: true, the default) splits only the failed batch and re-queues the smaller pieces; successful batches in the same round are kept.
Aggregate functions (llm_reduce, llm_rerank, llm_first, llm_last):
- Flock shrinks the working batch by 10% on token-limit errors and retries the same rows.
- If the batch size reaches zero, Flock raises an error instead of returning
NULL.
usage_limit, which tracks cumulative token quotas and fails immediately once exceeded.
batch_size (deprecated)
batch_size is a deprecated alias for max_batch_size. Existing models and inline overrides that use batch_size continue to work, but Flock logs a warning when batch_size is used.
Prefer max_batch_size in new models and queries. If both are set, max_batch_size takes precedence.
is_async
is_async applies to llm_complete and llm_filter. When true (the default), all batches are queued in parallel and responses are collected in a single call. When false, batches are processed one at a time synchronously.
is_async inline when calling a function:
rate_limit
rate_limit sets the maximum number of provider requests per minute for a Flock model, keyed by model_name. This helps avoid exceeding provider quotas on free or shared API tiers.
When rate_limit is set:
- Flock spaces outgoing provider requests so the configured requests-per-minute cap is not exceeded.
max_batch_sizeandrate_limitare independent:max_batch_sizecontrols tuples per request;rate_limitthrottles how many provider requests are sent per minute.- The limit applies across completions, embeddings, and transcriptions for that model.
- Sync and async scalar execution both respect the same per-model limit.
rate_limit is omitted, Flock does not apply request-per-minute throttling.
usage_limit
usage_limit sets cumulative token quotas for a Flock model, keyed by model_name. Like rate_limit, it is scoped per model; unlike rate_limit, which throttles how many provider requests are sent per minute, usage_limit tracks provider-reported token usage across calls and fails once a quota is exceeded.
Supported fields (at least one is required):
prompt_tokens_limit: maximum cumulative input/prompt tokenscompletion_tokens_limit: maximum cumulative output/completion tokenstotal_tokens_limit: maximum cumulative total tokens (prompt + completion)
max_batch_size retries (see above).
usage_limit is omitted, Flock does not enforce cumulative token quotas.
2. Management Commands
- Retrieve all available models
- Retrieve details of a specific model
- Create a new user-defined model
- Modify an existing user-defined model
- Remove a user-defined model
3. Global and Local Models
Model creation is database specific. If you want it to be available irrespective of the database, use the GLOBAL keyword. LOCAL is the default if not specified.Create Models
- Create a global model:
- Create a local model (default if no type is specified):
- Toggle a model’s state between global and local:

